root/drivers/char/stallion.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. init_module
  2. cleanup_module
  3. stl_meminit
  4. stl_memhalt
  5. stl_memalloc
  6. stl_open
  7. stl_waitcarrier
  8. stl_close
  9. stl_delay
  10. stl_write
  11. stl_putchar
  12. stl_flushchars
  13. stl_writeroom
  14. stl_charsinbuffer
  15. stl_getserial
  16. stl_setserial
  17. stl_ioctl
  18. stl_settermios
  19. stl_throttle
  20. stl_unthrottle
  21. stl_stop
  22. stl_start
  23. stl_hangup
  24. stl_flushbuffer
  25. stl_getreg
  26. stl_setreg
  27. stl_updatereg
  28. stl_txisr
  29. stl_rxisr
  30. stl_mdmisr
  31. stl_intr
  32. stl_offintr
  33. stl_ccrwait
  34. stl_setport
  35. stl_setsignals
  36. stl_getsignals
  37. stl_enablerxtx
  38. stl_startrxtx
  39. stl_disableintrs
  40. stl_sendbreak
  41. stl_mapirq
  42. stl_initports
  43. stl_initeio
  44. stl_initech
  45. stl_brdinit
  46. stl_findpcibrds
  47. stl_initbrds
  48. stl_init

   1 /*****************************************************************************/
   2 
   3 /*
   4  *      stallion.c  -- stallion multiport serial driver.
   5  *
   6  *      Copyright (C) 1994,1995  Greg Ungerer (gerg@stallion.oz.au).
   7  *
   8  *      This code is loosely based on the Linux serial driver, written by
   9  *      Linus Torvalds, Theodore T'so and others.
  10  *
  11  *      This program is free software; you can redistribute it and/or modify
  12  *      it under the terms of the GNU General Public License as published by
  13  *      the Free Software Foundation; either version 2 of the License, or
  14  *      (at your option) any later version.
  15  *
  16  *      This program is distributed in the hope that it will be useful,
  17  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  18  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19  *      GNU General Public License for more details.
  20  *
  21  *      You should have received a copy of the GNU General Public License
  22  *      along with this program; if not, write to the Free Software
  23  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24  */
  25 
  26 /*****************************************************************************/
  27 
  28 #ifdef MODULE
  29 #include <linux/config.h>
  30 #include <linux/module.h>
  31 #include <linux/version.h>
  32 #endif
  33 
  34 #include <linux/errno.h>
  35 #include <linux/sched.h>
  36 #include <linux/wait.h>
  37 #include <linux/interrupt.h>
  38 #include <linux/termios.h>
  39 #include <linux/fcntl.h>
  40 #include <linux/tty_driver.h>
  41 #include <linux/tty.h>
  42 #include <linux/tty_flip.h>
  43 #include <linux/serial.h>
  44 #include <linux/cd1400.h>
  45 #include <linux/string.h>
  46 #include <linux/malloc.h>
  47 #include <linux/ioport.h>
  48 #include <asm/system.h>
  49 #include <asm/io.h>
  50 #include <asm/segment.h>
  51 
  52 #ifdef CONFIG_PCI
  53 #include <linux/pci.h>
  54 #include <linux/bios32.h>
  55 #endif
  56 
  57 /*****************************************************************************/
  58 
  59 /*
  60  *      Define different board types. At the moment I have only declared
  61  *      those boards that this driver supports. But I will use the standard
  62  *      "assigned" board numbers. In the future this driver will support
  63  *      some of the other Stallion boards. Currently supported boards are
  64  *      abbreviated as EIO = EasyIO and ECH = EasyConnection 8/32.
  65  */
  66 #define BRD_EASYIO      20
  67 #define BRD_ECH         21
  68 #define BRD_ECHMC       22
  69 #define BRD_ECHPCI      26
  70 
  71 /*
  72  *      Define a configuration structure to hold the board configuration.
  73  *      Need to set this up in the code (for now) with the boards that are
  74  *      to be configured into the system. This is what needs to be modified
  75  *      when adding/removing/modifying boards. Each line entry in the
  76  *      stl_brdconf[] array is a board. Each line contains io/irq/memory
  77  *      ranges for that board (as well as what type of board it is).
  78  *      Some examples:
  79  *              { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 }
  80  *      This line would configure an EasyIO board (4 or 8, no difference),
  81  *      at io addres 2a0 and irq 10.
  82  *      Another example:
  83  *              { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
  84  *      This line will configure an EasyConnection 8/32 board at primary io
  85  *      addres 2a8, secondary io address 280 and irq 12.
  86  *      Enter as many lines into this array as you want (only the first 4
  87  *      will actually be used!). Any combination of EasyIO and EasyConnection
  88  *      boards can be specified. EasyConnection 8/32 boards can share their
  89  *      secondary io addresses between each other.
  90  *
  91  *      NOTE: there is no need to put any entries in this table for PCI
  92  *      boards. They will be found automatically by the driver - provided
  93  *      PCI BIOS32 support is compiled into the kernel.
  94  */
  95 
  96 typedef struct {
  97         int             brdtype;
  98         int             ioaddr1;
  99         int             ioaddr2;
 100         unsigned long   memaddr;
 101         int             irq;
 102         int             irqtype;
 103 } stlconf_t;
 104 
 105 static stlconf_t        stl_brdconf[] = {
 106         { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
 107 };
 108 
 109 static int      stl_nrbrds = sizeof(stl_brdconf) / sizeof(stlconf_t);
 110 
 111 /*****************************************************************************/
 112 
 113 /*
 114  *      Define some important driver characteristics. Device major numbers
 115  *      allocated as per Linux Device Registery.
 116  */
 117 #ifndef STL_SERIALMAJOR
 118 #define STL_SERIALMAJOR         24
 119 #endif
 120 #ifndef STL_CALLOUTMAJOR
 121 #define STL_CALLOUTMAJOR        25
 122 #endif
 123 
 124 #define STL_DRVTYPSERIAL        1
 125 #define STL_DRVTYPCALLOUT       2
 126 
 127 #define STL_MAXBRDS             4
 128 #define STL_MAXPANELS           4
 129 #define STL_PORTSPERPANEL       16
 130 #define STL_MAXPORTS            64
 131 #define STL_MAXDEVS             (STL_MAXBRDS * STL_MAXPORTS)
 132 
 133 /*
 134  *      I haven't really decided (or measured) what TX buffer size gives
 135  *      a good balance between performance and memory usage. These seem
 136  *      to work pretty well...
 137  */
 138 #define STL_TXBUFLOW            256
 139 #define STL_TXBUFSIZE           2048
 140 
 141 /*****************************************************************************/
 142 
 143 /*
 144  *      Define our local driver identity first. Set up stuff to deal with
 145  *      all the local structures required by a serial tty driver.
 146  */
 147 static char     *stl_drvname = "Stallion Multiport Serial Driver";
 148 static char     *stl_drvversion = "1.0.0";
 149 static char     *stl_serialname = "ttyE";
 150 static char     *stl_calloutname = "cue";
 151 
 152 static struct tty_driver        stl_serial;
 153 static struct tty_driver        stl_callout;
 154 static struct tty_struct        *stl_ttys[STL_MAXDEVS];
 155 static struct termios           *stl_termios[STL_MAXDEVS];
 156 static struct termios           *stl_termioslocked[STL_MAXDEVS];
 157 static int                      stl_refcount = 0;
 158 
 159 /*
 160  *      We will need to allocate a temporary write buffer for chars that
 161  *      come direct from user space. The problem is that a copy from user
 162  *      space might cause a page fault (typically on a system that is
 163  *      swapping!). All ports will share one buffer - since if the system
 164  *      is already swapping a shared buffer won't make things any worse.
 165  */
 166 static char                     *stl_tmpwritebuf;
 167 static struct semaphore         stl_tmpwritesem = MUTEX;
 168 
 169 /*
 170  *      Define a local default termios struct. All ports will be created
 171  *      with this termios initially. Basically all it defines is a raw port
 172  *      at 9600, 8 data bits, 1 stop bit.
 173  */
 174 static struct termios           stl_deftermios = {
 175         0,
 176         0,
 177         (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
 178         0,
 179         0,
 180         INIT_C_CC
 181 };
 182 
 183 /*
 184  *      Keep track of what interrupts we have requested for us.
 185  *      We don't need to request an interrupt twice if it is being
 186  *      shared with another Stallion board.
 187  */
 188 static int      stl_gotintrs[STL_MAXBRDS];
 189 static int      stl_numintrs = 0;
 190 
 191 /*****************************************************************************/
 192 
 193 /*
 194  *      Define a set of structures to hold all the board/panel/port info
 195  *      for our ports. These will be dynamically allocated as required.
 196  */
 197 
 198 /*
 199  *      Define a ring queue structure for each port. This will hold the
 200  *      TX data waiting to be output. Characters are fed into this buffer
 201  *      from the line discipline (or even direct from user space!) and
 202  *      then fed into the UARTs during interrupts. Will use a clasic ring
 203  *      queue here for this. The good thing about this type of ring queue
 204  *      is that the head and tail pointers can be updated without interrupt
 205  *      protection - since "write" code only needs to change the head, and
 206  *      interrupt code only needs to change the tail.
 207  */
 208 typedef struct {
 209         char    *buf;
 210         char    *head;
 211         char    *tail;
 212 } stlrq_t;
 213 
 214 /*
 215  *      Port, panel and board structures to hold status info about each.
 216  *      The board structure contains pointers to structures for each panel
 217  *      connected to it, and in turn each panel structure contains pointers
 218  *      for each port structure for each port on that panel. Note that
 219  *      the port structure also contains the board and panel number that it
 220  *      is associated with, this makes it (fairly) easy to get back to the
 221  *      board/panel info for a port.
 222  */
 223 typedef struct {
 224         int                     portnr;
 225         int                     panelnr;
 226         int                     brdnr;
 227         int                     ioaddr;
 228         int                     uartaddr;
 229         int                     pagenr;
 230         int                     istate;
 231         int                     flags;
 232         int                     baud_base;
 233         int                     custom_divisor;
 234         int                     close_delay;
 235         int                     closing_wait;
 236         int                     refcount;
 237         int                     openwaitcnt;
 238         int                     brklen;
 239         long                    session;
 240         long                    pgrp;
 241         unsigned int            sigs;
 242         unsigned int            rxignoremsk;
 243         unsigned int            rxmarkmsk;
 244         struct tty_struct       *tty;
 245         struct wait_queue       *open_wait;
 246         struct wait_queue       *close_wait;
 247         struct termios          normaltermios;
 248         struct termios          callouttermios;
 249         struct tq_struct        tqueue;
 250         stlrq_t                 tx;
 251 } stlport_t;
 252 
 253 typedef struct {
 254         int             panelnr;
 255         int             brdnr;
 256         int             pagenr;
 257         int             nrports;
 258         int             iobase;
 259         unsigned int    ackmask;
 260         stlport_t       *ports[STL_PORTSPERPANEL];
 261 } stlpanel_t;
 262 
 263 typedef struct {
 264         int             brdnr;
 265         int             brdtype;
 266         int             state;
 267         int             nrpanels;
 268         int             nrports;
 269         int             irq;
 270         int             irqtype;
 271         unsigned int    ioaddr1;
 272         unsigned int    ioaddr2;
 273         unsigned int    iostatus;
 274         unsigned int    ioctrl;
 275         unsigned int    ioctrlval;
 276         stlpanel_t      *panels[STL_MAXPANELS];
 277 } stlbrd_t;
 278 
 279 static stlbrd_t         *stl_brds[STL_MAXBRDS];
 280 
 281 /*
 282  *      Per board state flags. Used with the state field of the board struct.
 283  *      Not really much here yet!
 284  */
 285 #define BRD_FOUND       0x1
 286 
 287 /*
 288  *      Define the port structure istate flags. These set of flags are
 289  *      modified at interrupt time - so setting and reseting them needs
 290  *      to be atomic. Use the bit clear/setting routines for this.
 291  */
 292 #define ASYI_TXBUSY     1
 293 #define ASYI_TXLOW      2
 294 #define ASYI_DCDCHANGE  3
 295 
 296 /*
 297  *      Define an array of board names as printable strings. Handy for
 298  *      referencing boards when printing trace and stuff.
 299  */
 300 static char     *stl_brdnames[] = {
 301         (char *) NULL,
 302         (char *) NULL,
 303         (char *) NULL,
 304         (char *) NULL,
 305         (char *) NULL,
 306         (char *) NULL,
 307         (char *) NULL,
 308         (char *) NULL,
 309         (char *) NULL,
 310         (char *) NULL,
 311         (char *) NULL,
 312         (char *) NULL,
 313         (char *) NULL,
 314         (char *) NULL,
 315         (char *) NULL,
 316         (char *) NULL,
 317         (char *) NULL,
 318         (char *) NULL,
 319         (char *) NULL,
 320         (char *) NULL,
 321         "EasyIO",
 322         "EC8/32-AT",
 323         "EC8/32-MC",
 324         (char *) NULL,
 325         (char *) NULL,
 326         (char *) NULL,
 327         "EC8/32-PCI",
 328 };
 329 
 330 /*****************************************************************************/
 331 
 332 /*
 333  *      Hardware ID bits for the EasyIO and ECH boards. These defines apply
 334  *      to the directly accessable io ports of these boards (not the cd1400
 335  *      uarts - they are in cd1400.h).
 336  */
 337 #define EIO_8PORTRS     0x04
 338 #define EIO_4PORTRS     0x05
 339 #define EIO_8PORTDI     0x00
 340 #define EIO_8PORTM      0x06
 341 #define EIO_IDBITMASK   0x07
 342 #define EIO_INTRPEND    0x08
 343 #define EIO_INTEDGE     0x00
 344 #define EIO_INTLEVEL    0x08
 345 
 346 #define ECH_ID          0xa0
 347 #define ECH_IDBITMASK   0xe0
 348 #define ECH_BRDENABLE   0x08
 349 #define ECH_BRDDISABLE  0x00
 350 #define ECH_INTENABLE   0x01
 351 #define ECH_INTDISABLE  0x00
 352 #define ECH_INTLEVEL    0x02
 353 #define ECH_INTEDGE     0x00
 354 #define ECH_INTRPEND    0x01
 355 #define ECH_BRDRESET    0x01
 356 
 357 #define ECHMC_INTENABLE 0x01
 358 #define ECHMC_BRDRESET  0x02
 359 
 360 #define ECH_PNLSTATUS   2
 361 #define ECH_PNL16PORT   0x20
 362 #define ECH_PNLIDMASK   0x07
 363 #define ECH_PNLINTRPEND 0x80
 364 #define ECH_ADDR2MASK   0x1e0
 365 
 366 /*
 367  *      Define the offsets within the register bank for all io registers.
 368  *      These io address offsets are common to both the EIO and ECH.
 369  */
 370 #define EREG_ADDR       0
 371 #define EREG_DATA       4
 372 #define EREG_RXACK      5
 373 #define EREG_TXACK      6
 374 #define EREG_MDACK      7
 375 
 376 #define EREG_BANKSIZE   8
 377 
 378 /*
 379  *      Define the vector mapping bits for the programmable interrupt board
 380  *      hardware. These bits encode the interrupt for the board to use - it
 381  *      is software selectable (except the EIO-8M).
 382  */
 383 static unsigned char    stl_vecmap[] = {
 384         0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
 385         0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
 386 };
 387 
 388 /*
 389  *      Set up enable and disable macros for the ECH boards. They require
 390  *      the secondary io address space to be activated and deactivated.
 391  *      This way all ECH boards can share their secondary io region.
 392  *      If this is an ECH-PCI board then also need to set the page pointer
 393  *      to point to the correct page.
 394  */
 395 #define BRDENABLE(brdnr,pagenr)                                         \
 396         if (stl_brds[(brdnr)]->brdtype == BRD_ECH)                      \
 397                 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE),    \
 398                         stl_brds[(brdnr)]->ioctrl);                     \
 399         else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI)              \
 400                 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
 401 
 402 #define BRDDISABLE(brdnr)                                               \
 403         if (stl_brds[(brdnr)]->brdtype == BRD_ECH)                      \
 404                 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE),   \
 405                         stl_brds[(brdnr)]->ioctrl);
 406 
 407 /*
 408  *      Define the cd1400 baud rate clocks. These are used when calculating
 409  *      what clock and divisor to use for the required baud rate. Also
 410  *      define the maximum baud rate allowed, and the default base baud.
 411  */
 412 static int      stl_cd1400clkdivs[] = {
 413         CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
 414 };
 415 
 416 #define STL_MAXBAUD     230400
 417 #define STL_BAUDBASE    115200
 418 #define STL_CLOSEDELAY  50
 419 
 420 /*****************************************************************************/
 421 
 422 /*
 423  *      Define macros to extract a brd/port number from a minor number.
 424  */
 425 #define MKDEV2BRD(min)          (((min) & 0xc0) >> 6)
 426 #define MKDEV2PORT(min)         ((min) & 0x3f)
 427 
 428 /*
 429  *      Define a baud rate table that converts termios baud rate selector
 430  *      into the actual baud rate value. All baud rate calculates are based
 431  *      on the actual baud rate required.
 432  */
 433 static unsigned int     stl_baudrates[] = {
 434         0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
 435         9600, 19200, 38400, 57600, 115200, 230400
 436 };
 437 
 438 /*****************************************************************************/
 439 
 440 /*
 441  *      Memory allocation vars. These keep track of what memory allocation
 442  *      we can currently use. They help deal with memory in a consistent
 443  *      way, whether during init or run-time.
 444  */
 445 static int      stl_meminited = 0;
 446 static long     stl_memend;
 447 
 448 /*****************************************************************************/
 449 
 450 /*
 451  *      Define some handy local macros...
 452  */
 453 #ifndef MIN
 454 #define MIN(a,b)                (((a) <= (b)) ? (a) : (b))
 455 #endif
 456 
 457 /*****************************************************************************/
 458 
 459 /*
 460  *      Declare all those functions in this driver!
 461  */
 462 
 463 #ifdef MODULE
 464 int             init_module(void);
 465 void            cleanup_module(void);
 466 #else
 467 static void     stl_meminit(long base);
 468 static long     stl_memhalt(void);
 469 #endif
 470 static void     *stl_memalloc(int len);
 471 
 472 long            stl_init(long kmem_start);
 473 static int      stl_open(struct tty_struct *tty, struct file *filp);
 474 static void     stl_close(struct tty_struct *tty, struct file *filp);
 475 static int      stl_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count);
 476 static void     stl_putchar(struct tty_struct *tty, unsigned char ch);
 477 static void     stl_flushchars(struct tty_struct *tty);
 478 static int      stl_writeroom(struct tty_struct *tty);
 479 static int      stl_charsinbuffer(struct tty_struct *tty);
 480 static int      stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
 481 static void     stl_settermios(struct tty_struct *tty, struct termios *old);
 482 static void     stl_throttle(struct tty_struct *tty);
 483 static void     stl_unthrottle(struct tty_struct *tty);
 484 static void     stl_stop(struct tty_struct *tty);
 485 static void     stl_start(struct tty_struct *tty);
 486 static void     stl_flushbuffer(struct tty_struct *tty);
 487 static void     stl_hangup(struct tty_struct *tty);
 488 
 489 static int      stl_initbrds(void);
 490 static int      stl_brdinit(stlbrd_t *brdp);
 491 static int      stl_initeio(stlbrd_t *brdp);
 492 static int      stl_initech(stlbrd_t *brdp);
 493 static int      stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
 494 static int      stl_mapirq(int irq);
 495 static void     stl_getserial(stlport_t *portp, struct serial_struct *sp);
 496 static int      stl_setserial(stlport_t *portp, struct serial_struct *sp);
 497 static void     stl_setreg(stlport_t *portp, int regnr, int value);
 498 static int      stl_getreg(stlport_t *portp, int regnr);
 499 static int      stl_updatereg(stlport_t *portp, int regnr, int value);
 500 static void     stl_setport(stlport_t *portp, struct termios *tiosp);
 501 static void     stl_getsignals(stlport_t *portp);
 502 static void     stl_setsignals(stlport_t *portp, int dtr, int rts);
 503 static void     stl_ccrwait(stlport_t *portp);
 504 static void     stl_enablerxtx(stlport_t *portp, int rx, int tx);
 505 static void     stl_startrxtx(stlport_t *portp, int rx, int tx);
 506 static void     stl_disableintrs(stlport_t *portp);
 507 static void     stl_sendbreak(stlport_t *portp, long len);
 508 static int      stl_waitcarrier(stlport_t *portp, struct file *filp);
 509 static void     stl_delay(int len);
 510 static void     stl_intr(int irq, struct pt_regs *regs);
 511 static void     stl_offintr(void *private);
 512 
 513 #ifdef  CONFIG_PCI
 514 static int      stl_findpcibrds(void);
 515 #endif
 516 
 517 /*****************************************************************************/
 518 
 519 #ifdef MODULE
 520 
 521 /*
 522  *      Use the kernel version number for modules.
 523  */
 524 char    kernel_version[] = UTS_RELEASE;
 525 
 526 int init_module()
     /* [previous][next][first][last][top][bottom][index][help] */
 527 {
 528         unsigned long   flags;
 529 
 530 #if DEBUG
 531         printk("init_module()\n");
 532 #endif
 533 
 534         save_flags(flags);
 535         cli();
 536         stl_init(0);
 537         restore_flags(flags);
 538 
 539         return(0);
 540 }
 541 
 542 /*****************************************************************************/
 543 
 544 void cleanup_module()
     /* [previous][next][first][last][top][bottom][index][help] */
 545 {
 546         stlbrd_t        *brdp;
 547         stlpanel_t      *panelp;
 548         stlport_t       *portp;
 549         unsigned long   flags;
 550         int             i, j, k;
 551 
 552 #if DEBUG
 553         printk("cleanup_module()\n");
 554 #endif
 555 
 556         printk("Unloading %s: version %s\n", stl_drvname, stl_drvversion);
 557 
 558         save_flags(flags);
 559         cli();
 560 
 561 /*
 562  *      Free up all allocated resources used by the ports. This includes
 563  *      memory and interrupts. As part of this process we will also do
 564  *      a hangup on every open port - to try and flush out any processes
 565  *      hanging onto ports.
 566  */
 567         i = tty_unregister_driver(&stl_serial);
 568         j = tty_unregister_driver(&stl_callout);
 569         if (i || j) {
 570                 printk("STALLION: failed to un-register tty driver, errno=%d,%d\n", -i, -j);
 571                 restore_flags(flags);
 572                 return;
 573         }
 574 
 575         if (stl_tmpwritebuf != (char *) NULL)
 576                 kfree_s(stl_tmpwritebuf, STL_TXBUFSIZE);
 577 
 578         for (i = 0; (i < stl_nrbrds); i++) {
 579                 brdp = stl_brds[i];
 580                 for (j = 0; (j < STL_MAXPANELS); j++) {
 581                         panelp = brdp->panels[j];
 582                         if (panelp != (stlpanel_t *) NULL) {
 583                                 for (k = 0; (k < STL_PORTSPERPANEL); k++) {
 584                                         portp = panelp->ports[k];
 585                                         if (portp != (stlport_t *) NULL) {
 586                                                 if (portp->tty != (struct tty_struct *) NULL)
 587                                                         stl_hangup(portp->tty);
 588                                                 if (portp->tx.buf != (char *) NULL)
 589                                                         kfree_s(portp->tx.buf, STL_TXBUFSIZE);
 590                                                 kfree_s(portp, sizeof(stlport_t));
 591                                         }
 592                                 }
 593                                 kfree_s(panelp, sizeof(stlpanel_t));
 594                         }
 595                         
 596                 }
 597 
 598                 if (brdp->brdtype == BRD_ECH) {
 599                         release_region(brdp->ioaddr1, 2);
 600                         release_region(brdp->ioaddr2, 32);
 601                 } else if (brdp->brdtype == BRD_ECHPCI) {
 602                         release_region(brdp->ioaddr1, 4);
 603                         release_region(brdp->ioaddr2, 8);
 604                 } else if (brdp->brdtype == BRD_ECHMC) {
 605                         release_region(brdp->ioaddr1, 64);
 606                 } else if (brdp->brdtype == BRD_EASYIO) {
 607                         release_region(brdp->ioaddr1, 8);
 608                 }
 609 
 610                 kfree_s(brdp, sizeof(stlbrd_t));
 611                 stl_brds[i] = (stlbrd_t *) NULL;
 612         }
 613 
 614         for (i = 0; (i < stl_numintrs); i++)
 615                 free_irq(stl_gotintrs[i]);
 616 
 617         restore_flags(flags);
 618 }
 619 
 620 #endif
 621 
 622 /*****************************************************************************/
 623 
 624 /*
 625  *      Local memory allocation routines. These are used so we can deal with
 626  *      memory allocation at init time and during run-time in a consistent
 627  *      way. Everbody just calls the stl_memalloc routine to allocate
 628  *      memory and it will do the right thing.
 629  */
 630 
 631 #ifndef MODULE
 632 
 633 static void stl_meminit(long base)
     /* [previous][next][first][last][top][bottom][index][help] */
 634 {
 635         stl_memend = base;
 636         stl_meminited = 1;
 637 }
 638 
 639 static long stl_memhalt()
     /* [previous][next][first][last][top][bottom][index][help] */
 640 {
 641         stl_meminited = 0;
 642         return(stl_memend);
 643 }
 644 
 645 #endif
 646 
 647 static void *stl_memalloc(int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 648 {
 649         void    *mem;
 650 
 651         if (stl_meminited) {
 652                 mem = (void *) stl_memend;
 653                 stl_memend += len;
 654         } else {
 655                 mem = (void *) kmalloc(len, GFP_KERNEL);
 656         }
 657         return(mem);
 658 }
 659 
 660 /*****************************************************************************/
 661 
 662 static int stl_open(struct tty_struct *tty, struct file *filp)
     /* [previous][next][first][last][top][bottom][index][help] */
 663 {
 664         stlport_t       *portp;
 665         stlbrd_t        *brdp;
 666         unsigned int    minordev;
 667         int             brdnr, panelnr, portnr, rc;
 668 
 669 #if DEBUG
 670         printk("stl_open(tty=%x,filp=%x): device=%x\n", (int) tty, (int) filp, tty->device);
 671 #endif
 672 
 673         minordev = MINOR(tty->device);
 674         brdnr = MKDEV2BRD(minordev);
 675         if (brdnr >= stl_nrbrds)
 676                 return(-ENODEV);
 677         brdp = stl_brds[brdnr];
 678         if (brdp == (stlbrd_t *) NULL)
 679                 return(-ENODEV);
 680         minordev = MKDEV2PORT(minordev);
 681         for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
 682                 if (brdp->panels[panelnr] == (stlpanel_t *) NULL)
 683                         break;
 684                 if (minordev < brdp->panels[panelnr]->nrports) {
 685                         portnr = minordev;
 686                         break;
 687                 }
 688                 minordev -= brdp->panels[panelnr]->nrports;
 689         }
 690         if (portnr < 0)
 691                 return(-ENODEV);
 692 
 693         portp = brdp->panels[panelnr]->ports[portnr];
 694         if (portp == (stlport_t *) NULL)
 695                 return(-ENODEV);
 696 
 697 /*
 698  *      On the first open of the device setup the port hardware, and
 699  *      initialize the per port data structure.
 700  */
 701         portp->tty = tty;
 702         tty->driver_data = portp;
 703         portp->refcount++;
 704 
 705         if ((portp->flags & ASYNC_INITIALIZED) == 0) {
 706                 if (portp->tx.buf == (char *) NULL) {
 707                         portp->tx.buf = (char *) stl_memalloc(STL_TXBUFSIZE);
 708                         if (portp->tx.buf == (char *) NULL)
 709                                 return(-ENOMEM);
 710                         portp->tx.head = portp->tx.buf;
 711                         portp->tx.tail = portp->tx.buf;
 712                 }
 713                 stl_setport(portp, tty->termios);
 714                 stl_getsignals(portp);
 715                 stl_setsignals(portp, 1, 1);
 716                 stl_enablerxtx(portp, 1, 1);
 717                 stl_startrxtx(portp, 1, 0);
 718                 clear_bit(TTY_IO_ERROR, &tty->flags);
 719                 portp->flags |= ASYNC_INITIALIZED;
 720         }
 721 
 722 /*
 723  *      Check if this port is in the middle of closing. If so then wait
 724  *      until it is closed then return error status, based on flag settings.
 725  *      The sleep here does not need interrupt protection since the wakeup
 726  *      for it is done with the same context.
 727  */
 728         if (portp->flags & ASYNC_CLOSING) {
 729                 interruptible_sleep_on(&portp->close_wait);
 730                 if (portp->flags & ASYNC_HUP_NOTIFY)
 731                         return(-EAGAIN);
 732                 return(-ERESTARTSYS);
 733         }
 734 
 735 /*
 736  *      Based on type of open being done check if it can overlap with any
 737  *      previous opens still in effect. If we are a normal serial device
 738  *      then also we might have to wait for carrier.
 739  */
 740         if (tty->driver.subtype == STL_DRVTYPCALLOUT) {
 741                 if (portp->flags & ASYNC_NORMAL_ACTIVE)
 742                         return(-EBUSY);
 743                 if (portp->flags & ASYNC_CALLOUT_ACTIVE) {
 744                         if ((portp->flags & ASYNC_SESSION_LOCKOUT) &&
 745                                         (portp->session != current->session))
 746                                 return(-EBUSY);
 747                         if ((portp->flags & ASYNC_PGRP_LOCKOUT) &&
 748                                         (portp->pgrp != current->pgrp))
 749                                 return(-EBUSY);
 750                 }
 751                 portp->flags |= ASYNC_CALLOUT_ACTIVE;
 752         } else {
 753                 if (filp->f_flags & O_NONBLOCK) {
 754                         if (portp->flags & ASYNC_CALLOUT_ACTIVE)
 755                                 return(-EBUSY);
 756                 } else {
 757                         if ((rc = stl_waitcarrier(portp, filp)) != 0)
 758                                 return(rc);
 759                 }
 760                 portp->flags |= ASYNC_NORMAL_ACTIVE;
 761         }
 762 
 763         if ((portp->refcount == 1) && (portp->flags & ASYNC_SPLIT_TERMIOS)) {
 764                 if (tty->driver.subtype == STL_DRVTYPSERIAL)
 765                         *tty->termios = portp->normaltermios;
 766                 else
 767                         *tty->termios = portp->callouttermios;
 768                 stl_setport(portp, tty->termios);
 769         }
 770 
 771         portp->session = current->session;
 772         portp->pgrp = current->pgrp;
 773         return(0);
 774 }
 775 
 776 /*****************************************************************************/
 777 
 778 /*
 779  *      Possibly need to wait for carrier (DCD signal) to come high. Say
 780  *      maybe because if we are clocal then we don't need to wait...
 781  */
 782 
 783 static int stl_waitcarrier(stlport_t *portp, struct file *filp)
     /* [previous][next][first][last][top][bottom][index][help] */
 784 {
 785         unsigned long   flags;
 786         int             rc;
 787 
 788 #if DEBUG
 789         printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp, (int) filp);
 790 #endif
 791 
 792         rc = 0;
 793 
 794         save_flags(flags);
 795         cli();
 796         portp->openwaitcnt++;
 797         if (portp->refcount > 0)
 798                 portp->refcount--;
 799 
 800         for (;;) {
 801                 if ((portp->flags & ASYNC_CALLOUT_ACTIVE) == 0)
 802                         stl_setsignals(portp, 1, 1);
 803                 if (tty_hung_up_p(filp) || ((portp->flags & ASYNC_INITIALIZED) == 0)) {
 804                         if (portp->flags & ASYNC_HUP_NOTIFY)
 805                                 rc = -EBUSY;
 806                         else
 807                                 rc = -ERESTARTSYS;
 808                         break;
 809                 }
 810                 if (((portp->flags & ASYNC_CALLOUT_ACTIVE) == 0) &&
 811                                 ((portp->flags & ASYNC_CLOSING) == 0) &&
 812                                 ((portp->tty->termios->c_cflag & CLOCAL) ||
 813                                 (portp->sigs & TIOCM_CD))) {
 814                         break;
 815                 }
 816                 if (current->signal & ~current->blocked) {
 817                         rc = -ERESTARTSYS;
 818                         break;
 819                 }
 820                 interruptible_sleep_on(&portp->open_wait);
 821         }
 822 
 823         if (! tty_hung_up_p(filp))
 824                 portp->refcount++;
 825         portp->openwaitcnt--;
 826         restore_flags(flags);
 827 
 828         return(rc);
 829 }
 830 
 831 /*****************************************************************************/
 832 
 833 static void stl_close(struct tty_struct *tty, struct file *filp)
     /* [previous][next][first][last][top][bottom][index][help] */
 834 {
 835         stlport_t       *portp;
 836         unsigned long   flags;
 837 
 838 #if DEBUG
 839         printk("stl_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
 840 #endif
 841 
 842         portp = tty->driver_data;
 843         if (portp == (stlport_t *) NULL)
 844                 return;
 845 
 846         save_flags(flags);
 847         cli();
 848         if (tty_hung_up_p(filp)) {
 849                 restore_flags(flags);
 850                 return;
 851         }
 852         if (portp->refcount-- > 1) {
 853                 restore_flags(flags);
 854                 return;
 855         }
 856 
 857         portp->refcount = 0;
 858         portp->flags |= ASYNC_CLOSING;
 859 
 860         if (portp->flags & ASYNC_NORMAL_ACTIVE)
 861                 portp->normaltermios = *tty->termios;
 862         if (portp->flags & ASYNC_CALLOUT_ACTIVE)
 863                 portp->callouttermios = *tty->termios;
 864 
 865 /*
 866  *      May want to wait for any data to drain before closing. The BUSY
 867  *      flag keeps track of whether we are still sending or not - it allows
 868  *      for the FIFO in the cd1400.
 869  */
 870         tty->closing = 1;
 871         if (test_bit(ASYI_TXBUSY, &portp->istate)) {
 872                 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
 873                         tty_wait_until_sent(tty, portp->closing_wait);
 874         }
 875 
 876         portp->flags &= ~ASYNC_INITIALIZED;
 877         stl_disableintrs(portp);
 878         if (tty->termios->c_cflag & HUPCL)
 879                 stl_setsignals(portp, 0, 0);
 880         stl_enablerxtx(portp, 0, 0);
 881         stl_flushbuffer(tty);
 882         portp->istate = 0;
 883         if (portp->tx.buf != (char *) NULL) {
 884                 kfree_s(portp->tx.buf, STL_TXBUFSIZE);
 885                 portp->tx.buf = (char *) NULL;
 886                 portp->tx.head = (char *) NULL;
 887                 portp->tx.tail = (char *) NULL;
 888         }
 889         set_bit(TTY_IO_ERROR, &tty->flags);
 890         if (tty->ldisc.flush_buffer)
 891                 (tty->ldisc.flush_buffer)(tty);
 892 
 893         tty->closing = 0;
 894         tty->driver_data = (void *) NULL;
 895         portp->tty = (struct tty_struct *) NULL;
 896 
 897         if (portp->openwaitcnt) {
 898                 if (portp->close_delay)
 899                         stl_delay(portp->close_delay);
 900                 wake_up_interruptible(&portp->open_wait);
 901         }
 902 
 903         portp->flags &= ~(ASYNC_CALLOUT_ACTIVE | ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
 904         wake_up_interruptible(&portp->close_wait);
 905         restore_flags(flags);
 906 }
 907 
 908 /*****************************************************************************/
 909 
 910 /*
 911  *      Wait for a specified delay period, this is not a busy-loop. It will
 912  *      give up the processor while waiting. Unfortunately this has some
 913  *      rather intimate knowledge of the process management stuff.
 914  */
 915 
 916 static void stl_delay(int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 917 {
 918 #if DEBUG
 919         printk("stl_delay(len=%d)\n", len);
 920 #endif
 921         if (len > 0) {
 922                 current->state = TASK_INTERRUPTIBLE;
 923                 current->timeout = jiffies + len;
 924                 schedule();
 925         }
 926 }
 927 
 928 /*****************************************************************************/
 929 
 930 /*
 931  *      Write routine. Take data and stuff it in to the TX ring queue.
 932  *      If transmit interrupts are not running then start them.
 933  */
 934 
 935 static int stl_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count)
     /* [previous][next][first][last][top][bottom][index][help] */
 936 {
 937         stlport_t       *portp;
 938         unsigned int    len, stlen;
 939         unsigned long   flags;
 940         unsigned char   *chbuf;
 941         char            *head, *tail;
 942 
 943 #if DEBUG
 944         printk("stl_write(tty=%x,from_user=%d,buf=%x,count=%d)\n", (int) tty, from_user, (int) buf, count);
 945 #endif
 946 
 947         if ((tty == (struct tty_struct *) NULL) || (stl_tmpwritebuf == (char *) NULL))
 948                 return(0);
 949         portp = tty->driver_data;
 950         if (portp == (stlport_t *) NULL)
 951                 return(0);
 952         if (portp->tx.buf == (char *) NULL)
 953                 return(0);
 954 
 955 /*
 956  *      If copying direct from user space we must cater for page faults,
 957  *      causing us to "sleep" here for a while. To handle this copy in all
 958  *      the data we need now, into a local buffer. Then when we got it all
 959  *      copy it into the TX buffer.
 960  */
 961         chbuf = (unsigned char *) buf;
 962         if (from_user) {
 963                 head = portp->tx.head;
 964                 tail = portp->tx.tail;
 965                 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) :
 966                         (tail - head - 1);
 967                 count = MIN(len, count);
 968                 
 969                 save_flags(flags);
 970                 cli();
 971                 down(&stl_tmpwritesem);
 972                 memcpy_fromfs(stl_tmpwritebuf, chbuf, count);
 973                 up(&stl_tmpwritesem);
 974                 restore_flags(flags);
 975                 chbuf = &stl_tmpwritebuf[0];
 976         }
 977 
 978         head = portp->tx.head;
 979         tail = portp->tx.tail;
 980         if (head >= tail) {
 981                 len = STL_TXBUFSIZE - (head - tail) - 1;
 982                 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
 983         } else {
 984                 len = tail - head - 1;
 985                 stlen = len;
 986         }
 987 
 988         len = MIN(len, count);
 989         count = 0;
 990         while (len > 0) {
 991                 stlen = MIN(len, stlen);
 992                 memcpy(head, chbuf, stlen);
 993                 len -= stlen;
 994                 chbuf += stlen;
 995                 count += stlen;
 996                 head += stlen;
 997                 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
 998                         head = portp->tx.buf;
 999                         stlen = tail - head;
1000                 }
1001         }
1002         portp->tx.head = head;
1003 
1004         clear_bit(ASYI_TXLOW, &portp->istate);
1005         stl_startrxtx(portp, -1, 1);
1006 
1007         return(count);
1008 }
1009 
1010 /*****************************************************************************/
1011 
1012 static void stl_putchar(struct tty_struct *tty, unsigned char ch)
     /* [previous][next][first][last][top][bottom][index][help] */
1013 {
1014         stlport_t       *portp;
1015         unsigned int    len;
1016         char            *head, *tail;
1017 
1018 #if DEBUG
1019         printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1020 #endif
1021 
1022         if (tty == (struct tty_struct *) NULL)
1023                 return;
1024         portp = tty->driver_data;
1025         if (portp == (stlport_t *) NULL)
1026                 return;
1027         if (portp->tx.buf == (char *) NULL)
1028                 return;
1029 
1030         head = portp->tx.head;
1031         tail = portp->tx.tail;
1032 
1033         len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
1034         len--;
1035 
1036         if (len > 0) {
1037                 *head++ = ch;
1038                 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
1039                         head = portp->tx.buf;
1040         }       
1041         portp->tx.head = head;
1042 }
1043 
1044 /*****************************************************************************/
1045 
1046 /*
1047  *      If there are any characters in the buffer then make sure that TX
1048  *      interrupts are on and get'em out. Normally used after the putchar
1049  *      routine has been called.
1050  */
1051 
1052 static void stl_flushchars(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
1053 {
1054         stlport_t       *portp;
1055 
1056 #if DEBUG
1057         printk("stl_flushchars(tty=%x)\n", (int) tty);
1058 #endif
1059 
1060         if (tty == (struct tty_struct *) NULL)
1061                 return;
1062         portp = tty->driver_data;
1063         if (portp == (stlport_t *) NULL)
1064                 return;
1065         if (portp->tx.buf == (char *) NULL)
1066                 return;
1067 
1068 #if 0
1069         if (tty->stopped || tty->hw_stopped || (portp->tx.head == portp->tx.tail))
1070                 return;
1071 #endif
1072         stl_startrxtx(portp, -1, 1);
1073 }
1074 
1075 /*****************************************************************************/
1076 
1077 static int stl_writeroom(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
1078 {
1079         stlport_t       *portp;
1080         char            *head, *tail;
1081 
1082 #if DEBUG
1083         printk("stl_writeroom(tty=%x)\n", (int) tty);
1084 #endif
1085 
1086         if (tty == (struct tty_struct *) NULL)
1087                 return(0);
1088         portp = tty->driver_data;
1089         if (portp == (stlport_t *) NULL)
1090                 return(0);
1091         if (portp->tx.buf == (char *) NULL)
1092                 return(0);
1093 
1094         head = portp->tx.head;
1095         tail = portp->tx.tail;
1096         return((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
1097 }
1098 
1099 /*****************************************************************************/
1100 
1101 /*
1102  *      Return number of chars in the TX buffer. Normally we would just
1103  *      calculate the number of chars in the buffer and return that, but if
1104  *      the buffer is empty and TX interrupts are still on then we return
1105  *      that the buffer still has 1 char in it. This way whoever called us
1106  *      will not think that ALL chars have drained - since the UART still
1107  *      must have some chars in it (we are busy after all).
1108  */
1109 
1110 static int stl_charsinbuffer(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
1111 {
1112         stlport_t       *portp;
1113         unsigned int    size;
1114         char            *head, *tail;
1115 
1116 #if DEBUG
1117         printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
1118 #endif
1119 
1120         if (tty == (struct tty_struct *) NULL)
1121                 return(0);
1122         portp = tty->driver_data;
1123         if (portp == (stlport_t *) NULL)
1124                 return(0);
1125         if (portp->tx.buf == (char *) NULL)
1126                 return(0);
1127 
1128         head = portp->tx.head;
1129         tail = portp->tx.tail;
1130         size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1131         if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1132                 size = 1;
1133         return(size);
1134 }
1135 
1136 /*****************************************************************************/
1137 
1138 /*
1139  *      Generate the serial struct info.
1140  */
1141 
1142 static void stl_getserial(stlport_t *portp, struct serial_struct *sp)
     /* [previous][next][first][last][top][bottom][index][help] */
1143 {
1144         struct serial_struct    sio;
1145         stlbrd_t                *brdp;
1146 
1147 #if DEBUG
1148         printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1149 #endif
1150 
1151         memset(&sio, 0, sizeof(struct serial_struct));
1152         sio.type = PORT_CIRRUS;
1153         sio.line = portp->portnr;
1154         sio.port = portp->ioaddr;
1155         sio.flags = portp->flags;
1156         sio.baud_base = portp->baud_base;
1157         sio.close_delay = portp->close_delay;
1158         sio.closing_wait = portp->closing_wait;
1159         sio.custom_divisor = portp->custom_divisor;
1160         sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1161         sio.hub6 = 0;
1162 
1163         brdp = stl_brds[portp->brdnr];
1164         if (brdp != (stlbrd_t *) NULL)
1165                 sio.irq = brdp->irq;
1166 
1167         memcpy_tofs(sp, &sio, sizeof(struct serial_struct));
1168 }
1169 
1170 /*****************************************************************************/
1171 
1172 /*
1173  *      Set port according to the serial struct info.
1174  *      At this point we do not do any auto-configure stuff, so we will
1175  *      just quietly ignore any requests to change irq, etc.
1176  */
1177 
1178 static int stl_setserial(stlport_t *portp, struct serial_struct *sp)
     /* [previous][next][first][last][top][bottom][index][help] */
1179 {
1180         struct serial_struct    sio;
1181 
1182 #if DEBUG
1183         printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1184 #endif
1185 
1186         memcpy_fromfs(&sio, sp, sizeof(struct serial_struct));
1187         if (!suser()) {
1188                 if ((sio.baud_base != portp->baud_base) ||
1189                                 (sio.close_delay != portp->close_delay) ||
1190                                 ((sio.flags & ~ASYNC_USR_MASK) != (portp->flags & ~ASYNC_USR_MASK)))
1191                         return(-EPERM);
1192         } 
1193 
1194         portp->flags = (portp->flags & ~ASYNC_USR_MASK) | (sio.flags & ASYNC_USR_MASK);
1195         portp->baud_base = sio.baud_base;
1196         portp->close_delay = sio.close_delay;
1197         portp->closing_wait = sio.closing_wait;
1198         portp->custom_divisor = sio.custom_divisor;
1199         stl_setport(portp, portp->tty->termios);
1200         return(0);
1201 }
1202 
1203 /*****************************************************************************/
1204 
1205 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
     /* [previous][next][first][last][top][bottom][index][help] */
1206 {
1207         stlport_t       *portp;
1208         int             rc;
1209 
1210 #if DEBUG
1211         printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n", (int) tty, (int) file, cmd, (int) arg);
1212 #endif
1213 
1214         if (tty == (struct tty_struct *) NULL)
1215                 return(-ENODEV);
1216         portp = tty->driver_data;
1217         if (portp == (stlport_t *) NULL)
1218                 return(-ENODEV);
1219 
1220         rc = 0;
1221 
1222         switch (cmd) {
1223         case TCSBRK:
1224                 if ((rc = tty_check_change(tty)) == 0) {
1225                         tty_wait_until_sent(tty, 0);
1226                         if (! arg)
1227                                 stl_sendbreak(portp, 250);
1228                 }
1229                 break;
1230         case TCSBRKP:
1231                 if ((rc = tty_check_change(tty)) == 0) {
1232                         tty_wait_until_sent(tty, 0);
1233                         stl_sendbreak(portp, (arg ? (arg * 100) : 250));
1234                 }
1235                 break;
1236         case TIOCGSOFTCAR:
1237                 if ((rc = verify_area(VERIFY_WRITE, (void *) arg, sizeof(long))) == 0)
1238                         put_fs_long(((tty->termios->c_cflag & CLOCAL) ? 1 : 0), (unsigned long *) arg);
1239                 break;
1240         case TIOCSSOFTCAR:
1241                 if ((rc = verify_area(VERIFY_READ, (void *) arg, sizeof(long))) == 0) {
1242                         arg = get_fs_long((unsigned long *) arg);
1243                         tty->termios->c_cflag = (tty->termios->c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0);
1244                 }
1245                 break;
1246         case TIOCMGET:
1247                 if ((rc = verify_area(VERIFY_WRITE, (void *) arg, sizeof(unsigned int))) == 0) {
1248                         stl_getsignals(portp);
1249                         put_fs_long(portp->sigs, (unsigned long *) arg);
1250                 }
1251                 break;
1252         case TIOCMBIS:
1253                 if ((rc = verify_area(VERIFY_READ, (void *) arg, sizeof(long))) == 0) {
1254                         arg = get_fs_long((unsigned long *) arg);
1255                         stl_setsignals(portp, ((arg & TIOCM_DTR) ? 1 : -1), ((arg & TIOCM_RTS) ? 1 : -1));
1256                 }
1257                 break;
1258         case TIOCMBIC:
1259                 if ((rc = verify_area(VERIFY_READ, (void *) arg, sizeof(long))) == 0) {
1260                         arg = get_fs_long((unsigned long *) arg);
1261                         stl_setsignals(portp, ((arg & TIOCM_DTR) ? 0 : -1), ((arg & TIOCM_RTS) ? 0 : -1));
1262                 }
1263                 break;
1264         case TIOCMSET:
1265                 if ((rc = verify_area(VERIFY_READ, (void *) arg, sizeof(long))) == 0) {
1266                         arg = get_fs_long((unsigned long *) arg);
1267                         stl_setsignals(portp, ((arg & TIOCM_DTR) ? 1 : 0), ((arg & TIOCM_RTS) ? 1 : 0));
1268                 }
1269                 break;
1270         case TIOCGSERIAL:
1271                 if ((rc = verify_area(VERIFY_WRITE, (void *) arg, sizeof(struct serial_struct))) == 0)
1272                         stl_getserial(portp, (struct serial_struct *) arg);
1273                 break;
1274         case TIOCSSERIAL:
1275                 if ((rc = verify_area(VERIFY_READ, (void *) arg, sizeof(struct serial_struct))) == 0)
1276                         rc = stl_setserial(portp, (struct serial_struct *) arg);
1277                 break;
1278         case TIOCSERCONFIG:
1279         case TIOCSERGWILD:
1280         case TIOCSERSWILD:
1281         case TIOCSERGETLSR:
1282         case TIOCSERGSTRUCT:
1283         case TIOCSERGETMULTI:
1284         case TIOCSERSETMULTI:
1285         default:
1286                 rc = -ENOIOCTLCMD;
1287                 break;
1288         }
1289 
1290         return(rc);
1291 }
1292 
1293 /*****************************************************************************/
1294 
1295 static void stl_settermios(struct tty_struct *tty, struct termios *old)
     /* [previous][next][first][last][top][bottom][index][help] */
1296 {
1297         stlport_t       *portp;
1298         struct termios  *tiosp;
1299 
1300 #if DEBUG
1301         printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
1302 #endif
1303 
1304         if (tty == (struct tty_struct *) NULL)
1305                 return;
1306         portp = tty->driver_data;
1307         if (portp == (stlport_t *) NULL)
1308                 return;
1309 
1310         tiosp = tty->termios;
1311         if ((tiosp->c_cflag == old->c_cflag) && (tiosp->c_iflag == old->c_iflag))
1312                 return;
1313 
1314         stl_setport(portp, tiosp);
1315         stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0), -1);
1316         if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1317                 tty->hw_stopped = 0;
1318                 stl_start(tty);
1319         }
1320         if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1321                 wake_up_interruptible(&portp->open_wait);
1322 }
1323 
1324 /*****************************************************************************/
1325 
1326 /*
1327  *      Attempt to flow control who ever is sending us data. Based on termios
1328  *      settings use software or/and hardware flow control.
1329  */
1330 
1331 static void stl_throttle(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
1332 {
1333         stlport_t       *portp;
1334         unsigned long   flags;
1335 
1336 #if DEBUG
1337         printk("stl_throttle(tty=%x)\n", (int) tty);
1338 #endif
1339 
1340         if (tty == (struct tty_struct *) NULL)
1341                 return;
1342         portp = tty->driver_data;
1343         if (portp == (stlport_t *) NULL)
1344                 return;
1345 
1346         save_flags(flags);
1347         cli();
1348         BRDENABLE(portp->brdnr, portp->pagenr);
1349         stl_setreg(portp, CAR, (portp->portnr & 0x03));
1350         if (tty->termios->c_iflag & IXOFF) {
1351                 stl_ccrwait(portp);
1352                 stl_setreg(portp, CCR, CCR_SENDSCHR2);
1353                 stl_ccrwait(portp);
1354         }
1355         if (tty->termios->c_cflag & CRTSCTS) {
1356                 stl_setreg(portp, MCOR1, (stl_getreg(portp, MCOR1) & 0xf0));
1357                 stl_setreg(portp, MSVR2, 0);
1358         }
1359         BRDDISABLE(portp->brdnr);
1360         restore_flags(flags);
1361 }
1362 
1363 /*****************************************************************************/
1364 
1365 /*
1366  *      Unflow control the device sending us data...
1367  */
1368 
1369 static void stl_unthrottle(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
1370 {
1371         stlport_t       *portp;
1372         unsigned long   flags;
1373 
1374 #if DEBUG
1375         printk("stl_unthrottle(tty=%x)\n", (int) tty);
1376 #endif
1377 
1378         if (tty == (struct tty_struct *) NULL)
1379                 return;
1380         portp = tty->driver_data;
1381         if (portp == (stlport_t *) NULL)
1382                 return;
1383 
1384         save_flags(flags);
1385         cli();
1386         BRDENABLE(portp->brdnr, portp->pagenr);
1387         stl_setreg(portp, CAR, (portp->portnr & 0x03));
1388         if (tty->termios->c_iflag & IXOFF) {
1389                 stl_ccrwait(portp);
1390                 stl_setreg(portp, CCR, CCR_SENDSCHR1);
1391                 stl_ccrwait(portp);
1392         }
1393 /*
1394  *      Question: should we return RTS to what it was before? It may have
1395  *      been set by an ioctl... Suppose not, since if you have hardware
1396  *      flow control set then it is pretty silly to go and set the RTS line
1397  *      by hand.
1398  */
1399         if (tty->termios->c_cflag & CRTSCTS) {
1400                 stl_setreg(portp, MCOR1, (stl_getreg(portp, MCOR1) | FIFO_RTSTHRESHOLD));
1401                 stl_setreg(portp, MSVR2, MSVR2_RTS);
1402         }
1403         BRDDISABLE(portp->brdnr);
1404         restore_flags(flags);
1405 }
1406 
1407 /*****************************************************************************/
1408 
1409 /*
1410  *      Stop the transmitter. Basically to do this we will just turn TX
1411  *      interrupts off.
1412  */
1413 
1414 static void stl_stop(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
1415 {
1416         stlport_t       *portp;
1417 
1418 #if DEBUG
1419         printk("stl_stop(tty=%x)\n", (int) tty);
1420 #endif
1421 
1422         if (tty == (struct tty_struct *) NULL)
1423                 return;
1424         portp = tty->driver_data;
1425         if (portp == (stlport_t *) NULL)
1426                 return;
1427 
1428         stl_startrxtx(portp, -1, 0);
1429 }
1430 
1431 /*****************************************************************************/
1432 
1433 /*
1434  *      Start the transmitter again. Just turn TX interrupts back on.
1435  */
1436 
1437 static void stl_start(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
1438 {
1439         stlport_t       *portp;
1440 
1441 #if DEBUG
1442         printk("stl_start(tty=%x)\n", (int) tty);
1443 #endif
1444 
1445         if (tty == (struct tty_struct *) NULL)
1446                 return;
1447         portp = tty->driver_data;
1448         if (portp == (stlport_t *) NULL)
1449                 return;
1450 
1451         stl_startrxtx(portp, -1, 1);
1452 }
1453 
1454 /*****************************************************************************/
1455 
1456 /*
1457  *      Hangup this port. This is pretty much like closing the port, only
1458  *      a little more brutal. No waiting for data to drain. Shutdown the
1459  *      port and maybe drop signals.
1460  */
1461 
1462 static void stl_hangup(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
1463 {
1464         stlport_t       *portp;
1465 
1466 #if DEBUG
1467         printk("stl_hangup(tty=%x)\n", (int) tty);
1468 #endif
1469 
1470         if (tty == (struct tty_struct *) NULL)
1471                 return;
1472         portp = tty->driver_data;
1473         if (portp == (stlport_t *) NULL)
1474                 return;
1475 
1476         portp->flags &= ~ASYNC_INITIALIZED;
1477         stl_disableintrs(portp);
1478         if (tty->termios->c_cflag & HUPCL)
1479                 stl_setsignals(portp, 0, 0);
1480         stl_enablerxtx(portp, 0, 0);
1481         stl_flushbuffer(tty);
1482         portp->istate = 0;
1483         set_bit(TTY_IO_ERROR, &tty->flags);
1484         if (portp->tx.buf != (char *) NULL) {
1485                 kfree_s(portp->tx.buf, STL_TXBUFSIZE);
1486                 portp->tx.buf = (char *) NULL;
1487                 portp->tx.head = (char *) NULL;
1488                 portp->tx.tail = (char *) NULL;
1489         }
1490         tty->driver_data = (void *) NULL;
1491         portp->tty = (struct tty_struct *) NULL;
1492         portp->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CALLOUT_ACTIVE);
1493         portp->refcount = 0;
1494         wake_up_interruptible(&portp->open_wait);
1495 }
1496 
1497 /*****************************************************************************/
1498 
1499 static void stl_flushbuffer(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
1500 {
1501         stlport_t       *portp;
1502         unsigned long   flags;
1503 
1504 #if DEBUG
1505         printk("stl_flushbuffer(tty=%x)\n", (int) tty);
1506 #endif
1507 
1508         if (tty == (struct tty_struct *) NULL)
1509                 return;
1510         portp = tty->driver_data;
1511         if (portp == (stlport_t *) NULL)
1512                 return;
1513 
1514         save_flags(flags);
1515         cli();
1516         BRDENABLE(portp->brdnr, portp->pagenr);
1517         stl_setreg(portp, CAR, (portp->portnr & 0x03));
1518         stl_ccrwait(portp);
1519         stl_setreg(portp, CCR, CCR_TXFLUSHFIFO);
1520         stl_ccrwait(portp);
1521         portp->tx.tail = portp->tx.head;
1522         BRDDISABLE(portp->brdnr);
1523         restore_flags(flags);
1524 
1525         wake_up_interruptible(&tty->write_wait);
1526         if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup)
1527                 (tty->ldisc.write_wakeup)(tty);
1528 }
1529 
1530 /*****************************************************************************/
1531 
1532 /*
1533  *      These functions get/set/update the registers of the cd1400 UARTs.
1534  *      Access to the cd1400 registers is via an address/data io port pair.
1535  *      (Maybe should make this inline...)
1536  */
1537 
1538 static int stl_getreg(stlport_t *portp, int regnr)
     /* [previous][next][first][last][top][bottom][index][help] */
1539 {
1540         outb((regnr + portp->uartaddr), portp->ioaddr);
1541         return(inb(portp->ioaddr + EREG_DATA));
1542 }
1543 
1544 static void stl_setreg(stlport_t *portp, int regnr, int value)
     /* [previous][next][first][last][top][bottom][index][help] */
1545 {
1546         outb((regnr + portp->uartaddr), portp->ioaddr);
1547         outb(value, portp->ioaddr + EREG_DATA);
1548 }
1549 
1550 static int stl_updatereg(stlport_t *portp, int regnr, int value)
     /* [previous][next][first][last][top][bottom][index][help] */
1551 {
1552         outb((regnr + portp->uartaddr), portp->ioaddr);
1553         if (inb(portp->ioaddr + EREG_DATA) != value) {
1554                 outb(value, portp->ioaddr + EREG_DATA);
1555                 return(1);
1556         }
1557         return(0);
1558 }
1559 
1560 /*****************************************************************************/
1561 
1562 /*
1563  *      Transmit interrupt handler. This has gotta be fast!  Handling TX
1564  *      chars is pretty simple, stuff as many as possible from the TX buffer
1565  *      into the cd1400 FIFO. Must also handle TX breaks here, since they
1566  *      are embedded as commands in the data stream. Oh no, had to use a goto!
1567  *      This could be optimized more, will do when I get time...
1568  *      In practice it is possible that interrupts are enabled but that the
1569  *      port has been hung up. Need to handle not having any TX buffer here,
1570  *      this is done by using the side effect that head and tail will also
1571  *      be NULL if the buffer has been freed.
1572  */
1573 
1574 static inline void stl_txisr(stlpanel_t *panelp, int ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
1575 {
1576         stlport_t       *portp;
1577         int             len, stlen;
1578         char            *head, *tail;
1579         unsigned char   ioack, srer;
1580 
1581 #if DEBUG
1582         printk("stl_txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
1583 #endif
1584 
1585         ioack = inb(ioaddr + EREG_TXACK);
1586         if (((ioack & panelp->ackmask) != 0) || ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
1587                 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
1588                 return;
1589         }
1590         portp = panelp->ports[(ioack >> 3)];
1591 
1592 /*
1593  *      Unfortunately we need to handle breaks in the data stream, since
1594  *      this is the only way to generate them on the cd1400. Do it now if
1595  *      a break is to be sent.
1596  */
1597         if (portp->brklen != 0) {
1598                 if (portp->brklen > 0) {
1599                         outb((TDR + portp->uartaddr), ioaddr);
1600                         outb(ETC_CMD, (ioaddr + EREG_DATA));
1601                         outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
1602                         outb(ETC_CMD, (ioaddr + EREG_DATA));
1603                         outb(ETC_DELAY, (ioaddr + EREG_DATA));
1604                         outb(portp->brklen, (ioaddr + EREG_DATA));
1605                         outb(ETC_CMD, (ioaddr + EREG_DATA));
1606                         outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
1607                         portp->brklen = -1;
1608                         goto stl_txalldone;
1609                 } else {
1610                         outb((COR2 + portp->uartaddr), ioaddr);
1611                         outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC), (ioaddr + EREG_DATA));
1612                         portp->brklen = 0;
1613                 }
1614         }
1615 
1616         head = portp->tx.head;
1617         tail = portp->tx.tail;
1618         len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1619         if ((len == 0) || ((len < STL_TXBUFLOW) && (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
1620                 set_bit(ASYI_TXLOW, &portp->istate);
1621                 queue_task_irq_off(&portp->tqueue, &tq_scheduler);
1622         }
1623 
1624         if (len == 0) {
1625                 outb((SRER + portp->uartaddr), ioaddr);
1626                 srer = inb(ioaddr + EREG_DATA);
1627                 if (srer & SRER_TXDATA) {
1628                         srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
1629                 } else {
1630                         srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
1631                         clear_bit(ASYI_TXBUSY, &portp->istate);
1632                 }
1633                 outb(srer, (ioaddr + EREG_DATA));
1634         } else {
1635                 len = MIN(len, CD1400_TXFIFOSIZE);
1636                 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
1637                 outb((TDR + portp->uartaddr), ioaddr);
1638                 outsb((ioaddr + EREG_DATA), tail, stlen);
1639                 len -= stlen;
1640                 tail += stlen;
1641                 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
1642                         tail = portp->tx.buf;
1643                 if (len > 0) {
1644                         outsb((ioaddr + EREG_DATA), tail, len);
1645                         tail += len;
1646                 }
1647                 portp->tx.tail = tail;
1648         }
1649 
1650 stl_txalldone:
1651         outb((EOSRR + portp->uartaddr), ioaddr);
1652         outb(0, (ioaddr + EREG_DATA));
1653 }
1654 
1655 /*****************************************************************************/
1656 
1657 /*
1658  *      Receive character interrupt handler. Determine if we have good chars
1659  *      or bad chars and then process appropriately. Good chars are easy
1660  *      just shove the lot into the RX buffer and set all status byte to 0.
1661  *      If a bad RX char then process as required. This routine needs to be
1662  *      fast!  In practice it is possible that we get an interrupt on a port
1663  *      that is closed. This can happen on hangups - since they completely
1664  *      shutdown a port not in user context. Need to handle this case.
1665  */
1666 
1667 static inline void stl_rxisr(stlpanel_t *panelp, int ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
1668 {
1669         stlport_t               *portp;
1670         struct tty_struct       *tty;
1671         unsigned int            ioack, len, buflen;
1672         unsigned char           status;
1673         char                    ch;
1674         static char             unwanted[CD1400_RXFIFOSIZE];
1675 
1676 #if DEBUG
1677         printk("stl_rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
1678 #endif
1679 
1680         ioack = inb(ioaddr + EREG_RXACK);
1681         if ((ioack & panelp->ackmask) != 0) {
1682                 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
1683                 return;
1684         }
1685         portp = panelp->ports[(ioack >> 3)];
1686         tty = portp->tty;
1687 
1688         if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
1689                 outb((RDCR + portp->uartaddr), ioaddr);
1690                 len = inb(ioaddr + EREG_DATA);
1691                 if ((tty == (struct tty_struct *) NULL) || (tty->flip.char_buf_ptr == (char *) NULL) ||
1692                                 ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
1693                         outb((RDSR + portp->uartaddr), ioaddr);
1694                         insb((ioaddr + EREG_DATA), &unwanted[0], len);
1695                 } else {
1696                         len = MIN(len, buflen);
1697                         if (len > 0) {
1698                                 outb((RDSR + portp->uartaddr), ioaddr);
1699                                 insb((ioaddr + EREG_DATA), tty->flip.char_buf_ptr, len);
1700                                 memset(tty->flip.flag_buf_ptr, 0, len);
1701                                 tty->flip.flag_buf_ptr += len;
1702                                 tty->flip.char_buf_ptr += len;
1703                                 tty->flip.count += len;
1704                                 tty_schedule_flip(tty);
1705                         }
1706                 }
1707         } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
1708                 outb((RDSR + portp->uartaddr), ioaddr);
1709                 status = inb(ioaddr + EREG_DATA);
1710                 ch = inb(ioaddr + EREG_DATA);
1711                 if ((tty != (struct tty_struct *) NULL) && ((portp->rxignoremsk & status) == 0)) {
1712                         if (portp->rxmarkmsk & status) {
1713                                 if (status & ST_BREAK) {
1714                                         status = TTY_BREAK;
1715 #ifndef MODULE
1716                                         if (portp->flags & ASYNC_SAK)
1717                                                 do_SAK(tty);
1718 #endif
1719                                 } else if (status & ST_PARITY) {
1720                                         status = TTY_PARITY;
1721                                 } else if (status & ST_FRAMING) {
1722                                         status = TTY_FRAME;
1723                                 } else if(status & ST_OVERRUN) {
1724                                         status = TTY_OVERRUN;
1725                                 } else {
1726                                         status = 0;
1727                                 }
1728                         } else {
1729                                 status = 0;
1730                         }
1731                         if (tty->flip.char_buf_ptr != (char *) NULL) {
1732                                 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
1733                                         *tty->flip.flag_buf_ptr++ = status;
1734                                         *tty->flip.char_buf_ptr++ = ch;
1735                                         tty->flip.count++;
1736                                 }
1737                                 tty_schedule_flip(tty);
1738                         }
1739                 }
1740         } else {
1741                 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
1742                 return;
1743         }
1744 
1745         outb((EOSRR + portp->uartaddr), ioaddr);
1746         outb(0, (ioaddr + EREG_DATA));
1747 }
1748 
1749 /*****************************************************************************/
1750 
1751 /*
1752  *      Modem interrupt handler. The is called when the modem signal line
1753  *      (DCD) has changed state. Leave most of the work to the off-level
1754  *      processing routine.
1755  */
1756 
1757 static inline void stl_mdmisr(stlpanel_t *panelp, int ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
1758 {
1759         stlport_t       *portp;
1760         unsigned int    ioack;
1761         unsigned char   misr;
1762 
1763 #if DEBUG
1764         printk("stl_mdmisr(panelp=%x)\n", (int) panelp);
1765 #endif
1766 
1767         ioack = inb(ioaddr + EREG_MDACK);
1768         if (((ioack & panelp->ackmask) != 0) || ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
1769                 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
1770                 return;
1771         }
1772         portp = panelp->ports[(ioack >> 3)];
1773 
1774         outb((MISR + portp->uartaddr), ioaddr);
1775         misr = inb(ioaddr + EREG_DATA);
1776         if (misr & MISR_DCD) {
1777                 set_bit(ASYI_DCDCHANGE, &portp->istate);
1778                 queue_task_irq_off(&portp->tqueue, &tq_scheduler);
1779         }
1780 
1781         outb((EOSRR + portp->uartaddr), ioaddr);
1782         outb(0, (ioaddr + EREG_DATA));
1783 }
1784 
1785 /*****************************************************************************/
1786 
1787 /*
1788  *      Interrupt handler for EIO and ECH boards. This code ain't all that
1789  *      pretty, but the idea is to make it as fast as possible. This code is
1790  *      well suited to be assemblerized :-)  We don't use the general purpose
1791  *      register access functions here, for speed we will go strait to the
1792  *      io region.
1793  */
1794 
1795 static void stl_intr(int irq, struct pt_regs *regs)
     /* [previous][next][first][last][top][bottom][index][help] */
1796 {
1797         stlbrd_t        *brdp;
1798         stlpanel_t      *panelp;
1799         unsigned char   svrtype;
1800         int             i, panelnr, iobase;
1801 
1802 #if DEBUG
1803         printk("stl_intr(irq=%d,regs=%x)\n", irq, (int) regs);
1804 #endif
1805 
1806         panelp = (stlpanel_t *) NULL;
1807         for (i = 0; (i < stl_nrbrds); ) {
1808                 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL) {
1809                         i++;
1810                         continue;
1811                 }
1812                 if (brdp->state == 0) {
1813                         i++;
1814                         continue;
1815                 }
1816 /*
1817  *              The following section of code handles the subtle differences
1818  *              between board types. It is sort of similar, but different
1819  *              enough to handle each separately.
1820  */
1821                 if (brdp->brdtype == BRD_EASYIO) {
1822                         if ((inb(brdp->iostatus) & EIO_INTRPEND) == 0) {
1823                                 i++;
1824                                 continue;
1825                         }
1826                         panelp = brdp->panels[0];
1827                         iobase = panelp->iobase;
1828                         outb(SVRR, iobase);
1829                         svrtype = inb(iobase + EREG_DATA);
1830                         if (brdp->nrports > 4) {
1831                                 outb((SVRR + 0x80), iobase);
1832                                 svrtype |= inb(iobase + EREG_DATA);
1833                         }
1834                 } else if (brdp->brdtype == BRD_ECH) {
1835                         if ((inb(brdp->iostatus) & ECH_INTRPEND) == 0) {
1836                                 i++;
1837                                 continue;
1838                         }
1839                         outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
1840                         for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1841                                 panelp = brdp->panels[panelnr];
1842                                 iobase = panelp->iobase;
1843                                 if (inb(iobase + ECH_PNLSTATUS) & ECH_PNLINTRPEND)
1844                                         break;
1845                                 if (panelp->nrports > 8) {
1846                                         iobase += 0x8;
1847                                         if (inb(iobase + ECH_PNLSTATUS) & ECH_PNLINTRPEND)
1848                                                 break;
1849                                 }
1850                         }       
1851                         if (panelnr >= brdp->nrpanels) {
1852                                 i++;
1853                                 continue;
1854                         }
1855                         outb(SVRR, iobase);
1856                         svrtype = inb(iobase + EREG_DATA);
1857                         outb((SVRR + 0x80), iobase);
1858                         svrtype |= inb(iobase + EREG_DATA);
1859                 } else if (brdp->brdtype == BRD_ECHPCI) {
1860                         iobase = brdp->ioaddr2;
1861                         for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1862                                 panelp = brdp->panels[panelnr];
1863                                 outb(panelp->pagenr, brdp->ioctrl);
1864                                 if (inb(iobase + ECH_PNLSTATUS) & ECH_PNLINTRPEND)
1865                                         break;
1866                                 if (panelp->nrports > 8) {
1867                                         outb((panelp->pagenr + 1), brdp->ioctrl);
1868                                         if (inb(iobase + ECH_PNLSTATUS) & ECH_PNLINTRPEND)
1869                                                 break;
1870                                 }
1871                         }       
1872                         if (panelnr >= brdp->nrpanels) {
1873                                 i++;
1874                                 continue;
1875                         }
1876                         outb(SVRR, iobase);
1877                         svrtype = inb(iobase + EREG_DATA);
1878                         outb((SVRR + 0x80), iobase);
1879                         svrtype |= inb(iobase + EREG_DATA);
1880                 } else if (brdp->brdtype == BRD_ECHMC) {
1881                         if ((inb(brdp->iostatus) & ECH_INTRPEND) == 0) {
1882                                 i++;
1883                                 continue;
1884                         }
1885                         for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1886                                 panelp = brdp->panels[panelnr];
1887                                 iobase = panelp->iobase;
1888                                 if (inb(iobase + ECH_PNLSTATUS) & ECH_PNLINTRPEND)
1889                                         break;
1890                                 if (panelp->nrports > 8) {
1891                                         iobase += 0x8;
1892                                         if (inb(iobase + ECH_PNLSTATUS) & ECH_PNLINTRPEND)
1893                                                 break;
1894                                 }
1895                         }       
1896                         if (panelnr >= brdp->nrpanels) {
1897                                 i++;
1898                                 continue;
1899                         }
1900                         outb(SVRR, iobase);
1901                         svrtype = inb(iobase + EREG_DATA);
1902                         outb((SVRR + 0x80), iobase);
1903                         svrtype |= inb(iobase + EREG_DATA);
1904                 } else {
1905                         printk("STALLION: unknown board type=%x\n", brdp->brdtype);
1906                         i++;
1907                         continue;
1908                 }
1909 
1910 /*
1911  *              We have determined what type of service is required for a
1912  *              port. From here on in the service of a port is the same no
1913  *              matter what the board type...
1914  */
1915                 if (svrtype & SVRR_RX)
1916                         stl_rxisr(panelp, iobase);
1917                 if (svrtype & SVRR_TX)
1918                         stl_txisr(panelp, iobase);
1919                 if (svrtype & SVRR_MDM)
1920                         stl_mdmisr(panelp, iobase);
1921 
1922                 if (brdp->brdtype == BRD_ECH)
1923                         outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
1924         }
1925 }
1926 
1927 /*****************************************************************************/
1928 
1929 /*
1930  *      Service an off-level request for some channel.
1931  */
1932 
1933 static void stl_offintr(void *private)
     /* [previous][next][first][last][top][bottom][index][help] */
1934 {
1935         stlport_t               *portp;
1936         struct tty_struct       *tty;
1937         unsigned int            oldsigs;
1938 
1939         portp = private;
1940 #if DEBUG
1941         printk("stl_offintr(portp=%x)\n", (int) portp);
1942 #endif
1943 
1944         if (portp == (stlport_t *) NULL)
1945                 return;
1946         tty = portp->tty;
1947         if (tty == (struct tty_struct *) NULL)
1948                 return;
1949 
1950         if (test_bit(ASYI_TXLOW, &portp->istate)) {
1951                 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup)
1952                         (tty->ldisc.write_wakeup)(tty);
1953                 wake_up_interruptible(&tty->write_wait);
1954         }
1955         if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
1956                 clear_bit(ASYI_DCDCHANGE, &portp->istate);
1957                 oldsigs = portp->sigs;
1958                 stl_getsignals(portp);
1959                 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
1960                         wake_up_interruptible(&portp->open_wait);
1961                 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
1962                         if (! ((portp->flags & ASYNC_CALLOUT_ACTIVE) &&
1963                                         (portp->flags & ASYNC_CALLOUT_NOHUP))) {
1964                                 tty_hangup(tty);
1965                         }
1966                 }
1967         }
1968 }
1969 
1970 /*****************************************************************************/
1971 
1972 /*
1973  *      Wait for the command register to be ready. We will poll this,
1974  *      since it won't usually take too long to be ready.
1975  */
1976 
1977 static void stl_ccrwait(stlport_t *portp)
     /* [previous][next][first][last][top][bottom][index][help] */
1978 {
1979         int     i;
1980 
1981         for (i = 0; (i < CCR_MAXWAIT); i++) {
1982                 if (stl_getreg(portp, CCR) == 0) {
1983                         return;
1984                 }
1985         }
1986 
1987         printk("STALLION: cd1400 device not responding, port=%d panel=%d brd=%d\n", portp->portnr, portp->panelnr, portp->brdnr);
1988 }
1989 
1990 /*****************************************************************************/
1991 
1992 /*
1993  *      Set up the cd1400 registers for a port based on the termios port
1994  *      settings.
1995  */
1996 
1997 static void stl_setport(stlport_t *portp, struct termios *tiosp)
     /* [previous][next][first][last][top][bottom][index][help] */
1998 {
1999         stlbrd_t        *brdp;
2000         unsigned long   flags;
2001         unsigned int    clkdiv, baudrate;
2002         unsigned char   cor1, cor2, cor3;
2003         unsigned char   cor4, cor5, ccr;
2004         unsigned char   srer, sreron, sreroff;
2005         unsigned char   mcor1, mcor2, rtpr;
2006         unsigned char   clk, div;
2007 
2008         cor1 = 0;
2009         cor2 = 0;
2010         cor3 = 0;
2011         cor4 = 0;
2012         cor5 = 0;
2013         ccr = 0;
2014         rtpr = 0;
2015         clk = 0;
2016         div = 0;
2017         mcor1 = 0;
2018         mcor2 = 0;
2019         sreron = 0;
2020         sreroff = 0;
2021 
2022         brdp = stl_brds[portp->brdnr];
2023         if (brdp == (stlbrd_t *) NULL)
2024                 return;
2025 
2026 /*
2027  *      Set up the RX char ignore mask with those RX error types we
2028  *      can ignore. We can get the cd1400 to help us out a little here,
2029  *      it will ignore parity errors and breaks for us.
2030  */
2031         portp->rxignoremsk = 0;
2032         if (tiosp->c_iflag & IGNPAR) {
2033                 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
2034                 cor1 |= COR1_PARIGNORE;
2035         }
2036         if (tiosp->c_iflag & IGNBRK) {
2037                 portp->rxignoremsk |= ST_BREAK;
2038                 cor4 |= COR4_IGNBRK;
2039         }
2040 
2041         portp->rxmarkmsk = ST_OVERRUN;
2042         if (tiosp->c_iflag & (INPCK | PARMRK))
2043                 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
2044         if (tiosp->c_iflag & BRKINT)
2045                 portp->rxmarkmsk |= ST_BREAK;
2046 
2047 /*
2048  *      Go through the char size, parity and stop bits and set all the
2049  *      option register appropriately.
2050  */
2051         switch (tiosp->c_cflag & CSIZE) {
2052         case CS5:
2053                 cor1 |= COR1_CHL5;
2054                 break;
2055         case CS6:
2056                 cor1 |= COR1_CHL6;
2057                 break;
2058         case CS7:
2059                 cor1 |= COR1_CHL7;
2060                 break;
2061         default:
2062                 cor1 |= COR1_CHL8;
2063                 break;
2064         }
2065 
2066         if (tiosp->c_cflag & CSTOPB)
2067                 cor1 |= COR1_STOP2;
2068         else
2069                 cor1 |= COR1_STOP1;
2070 
2071         if (tiosp->c_cflag & PARENB) {
2072                 if (tiosp->c_cflag & PARODD)
2073                         cor1 |= (COR1_PARENB | COR1_PARODD);
2074                 else
2075                         cor1 |= (COR1_PARENB | COR1_PAREVEN);
2076         } else {
2077                 cor1 |= COR1_PARNONE;
2078         }
2079 
2080 /*
2081  *      Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
2082  *      space for hardware flow control and the like. This should be set to
2083  *      VMIN. Also here we will set the RX data timeout to 10ms - this should
2084  *      really be based on VTIME.
2085  */
2086         cor3 |= FIFO_RXTHRESHOLD;
2087         rtpr = 2;
2088 
2089 /*
2090  *      Calculate the baud rate timers. For now we will just assume that
2091  *      the input and output baud are the same. Could have used a baud
2092  *      table here, but this way we can generate virtually any baud rate
2093  *      we like!
2094  */
2095         baudrate = tiosp->c_cflag & CBAUD;
2096         if (baudrate & CBAUDEX) {
2097                 baudrate &= ~CBAUDEX;
2098                 if ((baudrate < 1) || (baudrate > 2))
2099                         tiosp->c_cflag &= ~CBAUDEX;
2100                 else
2101                         baudrate += 15;
2102         }
2103         baudrate = stl_baudrates[baudrate];
2104         if ((tiosp->c_cflag & CBAUD) == B38400) {
2105                 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
2106                         baudrate = 57600;
2107                 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
2108                         baudrate = 115200;
2109                 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
2110                         baudrate = (portp->baud_base / portp->custom_divisor);
2111         }
2112         if (baudrate > STL_MAXBAUD)
2113                 baudrate = STL_MAXBAUD;
2114 
2115         if (baudrate > 0) {
2116                 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
2117                         clkdiv = ((CD1400_CLKHZ / stl_cd1400clkdivs[clk]) / baudrate);
2118                         if (clkdiv < 0x100)
2119                                 break;
2120                 }
2121                 div = (unsigned char) clkdiv;
2122         }
2123 
2124 /*
2125  *      Check what form of modem signaling is required and set it up.
2126  */
2127         if ((tiosp->c_cflag & CLOCAL) == 0) {
2128                 mcor1 |= MCOR1_DCD;
2129                 mcor2 |= MCOR2_DCD;
2130                 sreron |= SRER_MODEM;
2131         }
2132 
2133 /*
2134  *      Setup cd1400 enhanced modes if we can. In particular we want to
2135  *      handle as much of the flow control as possbile automatically. As
2136  *      well as saving a few CPU cycles it will also greatly improve flow
2137  *      control reliablilty.
2138  */
2139         if (tiosp->c_iflag & IXON) {
2140                 cor2 |= COR2_TXIBE;
2141                 cor3 |= (COR3_FCT | COR3_SCD12);
2142                 if (tiosp->c_iflag & IXANY)
2143                         cor2 |= COR2_IXM;
2144         }
2145 
2146         if (tiosp->c_cflag & CRTSCTS) {
2147                 cor2 |= COR2_CTSAE;
2148                 mcor1 |= FIFO_RTSTHRESHOLD;
2149         }
2150 
2151 /*
2152  *      All register cd1400 register values calculated so go through and set
2153  *      them all up.
2154  */
2155 
2156 #if DEBUG
2157         printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n", portp->portnr, portp->panelnr, portp->brdnr);
2158         printk("    cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n", cor1, cor2, cor3, cor4, cor5);
2159         printk("    mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n", mcor1, mcor2, rtpr, sreron, sreroff);
2160         printk("    tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
2161         printk("    schr1=%x schr2=%x schr3=%x schr4=%x\n", tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP], tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
2162 #endif
2163 
2164         save_flags(flags);
2165         cli();
2166         BRDENABLE(portp->brdnr, portp->pagenr);
2167         stl_setreg(portp, CAR, (portp->portnr & 0x3));
2168         srer = stl_getreg(portp, SRER);
2169         stl_setreg(portp, SRER, 0);
2170         if (stl_updatereg(portp, COR1, cor1))
2171                 ccr = 1;
2172         if (stl_updatereg(portp, COR2, cor2))
2173                 ccr = 1;
2174         if (stl_updatereg(portp, COR3, cor3))
2175                 ccr = 1;
2176         if (ccr) {
2177                 stl_ccrwait(portp);
2178                 stl_setreg(portp, CCR, CCR_CORCHANGE);
2179         }
2180         stl_setreg(portp, COR4, cor4);
2181         stl_setreg(portp, COR5, cor5);
2182         stl_setreg(portp, MCOR1, mcor1);
2183         stl_setreg(portp, MCOR2, mcor2);
2184         if (baudrate > 0) {
2185                 stl_setreg(portp, TCOR, clk);
2186                 stl_setreg(portp, TBPR, div);
2187                 stl_setreg(portp, RCOR, clk);
2188                 stl_setreg(portp, RBPR, div);
2189         }
2190         stl_setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
2191         stl_setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
2192         stl_setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
2193         stl_setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
2194         stl_setreg(portp, RTPR, rtpr);
2195         mcor1 = stl_getreg(portp, MSVR1);
2196         if (mcor1 & MSVR1_DCD)
2197                 portp->sigs |= TIOCM_CD;
2198         else
2199                 portp->sigs &= ~TIOCM_CD;
2200         stl_setreg(portp, SRER, ((srer & ~sreroff) | sreron));
2201         BRDDISABLE(portp->brdnr);
2202         restore_flags(flags);
2203 }
2204 
2205 /*****************************************************************************/
2206 
2207 /*
2208  *      Set the state of the DTR and RTS signals.
2209  */
2210 
2211 static void stl_setsignals(stlport_t *portp, int dtr, int rts)
     /* [previous][next][first][last][top][bottom][index][help] */
2212 {
2213         unsigned char   msvr1, msvr2;
2214         unsigned long   flags;
2215 
2216 #if DEBUG
2217         printk("stl_setsignals(portp=%x,dtr=%d,rts=%d)\n", (int) portp, dtr, rts);
2218 #endif
2219 
2220         msvr1 = 0;
2221         msvr2 = 0;
2222         if (dtr > 0)
2223                 msvr1 = MSVR1_DTR;
2224         if (rts > 0)
2225                 msvr2 = MSVR2_RTS;
2226 
2227         save_flags(flags);
2228         cli();
2229         BRDENABLE(portp->brdnr, portp->pagenr);
2230         stl_setreg(portp, CAR, (portp->portnr & 0x03));
2231         if (rts >= 0)
2232                 stl_setreg(portp, MSVR2, msvr2);
2233         if (dtr >= 0)
2234                 stl_setreg(portp, MSVR1, msvr1);
2235         BRDDISABLE(portp->brdnr);
2236         restore_flags(flags);
2237 }
2238 
2239 /*****************************************************************************/
2240 
2241 /*
2242  *      Get the state of the signals.
2243  */
2244 
2245 static void stl_getsignals(stlport_t *portp)
     /* [previous][next][first][last][top][bottom][index][help] */
2246 {
2247         unsigned char   msvr1, msvr2;
2248         unsigned long   flags;
2249 
2250 #if DEBUG
2251         printk("stl_getsignals(portp=%x)\n", (int) portp);
2252 #endif
2253 
2254         save_flags(flags);
2255         cli();
2256         BRDENABLE(portp->brdnr, portp->pagenr);
2257         stl_setreg(portp, CAR, (portp->portnr & 0x03));
2258         msvr1 = stl_getreg(portp, MSVR1);
2259         msvr2 = stl_getreg(portp, MSVR2);
2260         BRDDISABLE(portp->brdnr);
2261         portp->sigs = 0;
2262         portp->sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
2263         portp->sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
2264         portp->sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
2265         portp->sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
2266         portp->sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
2267         portp->sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
2268         restore_flags(flags);
2269 }
2270 
2271 /*****************************************************************************/
2272 
2273 /*
2274  *      Enable/Disable the Transmitter and/or Reciever.
2275  */
2276 
2277 static void stl_enablerxtx(stlport_t *portp, int rx, int tx)
     /* [previous][next][first][last][top][bottom][index][help] */
2278 {
2279         unsigned char   ccr;
2280         unsigned long   flags;
2281 
2282 #if DEBUG
2283         printk("stl_enablerxtx(portp=%x,rx=%d,tx=%d)\n", (int) portp, rx, tx);
2284 #endif
2285         ccr = 0;
2286 
2287         if (tx == 0)
2288                 ccr |= CCR_TXDISABLE;
2289         else if (tx > 0)
2290                 ccr |= CCR_TXENABLE;
2291         if (rx == 0)
2292                 ccr |= CCR_RXDISABLE;
2293         else if (rx > 0)
2294                 ccr |= CCR_RXENABLE;
2295 
2296         save_flags(flags);
2297         cli();
2298         BRDENABLE(portp->brdnr, portp->pagenr);
2299         stl_setreg(portp, CAR, (portp->portnr & 0x03));
2300         stl_ccrwait(portp);
2301         stl_setreg(portp, CCR, ccr);
2302         stl_ccrwait(portp);
2303         BRDDISABLE(portp->brdnr);
2304         restore_flags(flags);
2305 }
2306 
2307 /*****************************************************************************/
2308 
2309 /*
2310  *      Start/stop the Transmitter and/or Reciever.
2311  */
2312 
2313 static void stl_startrxtx(stlport_t *portp, int rx, int tx)
     /* [previous][next][first][last][top][bottom][index][help] */
2314 {
2315         unsigned char   sreron, sreroff;
2316         unsigned long   flags;
2317 
2318 #if DEBUG
2319         printk("stl_startrxtx(portp=%x,rx=%d,tx=%d)\n", (int) portp, rx, tx);
2320 #endif
2321 
2322         sreron = 0;
2323         sreroff = 0;
2324         if (tx == 0)
2325                 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
2326         else if (tx == 1)
2327                 sreron |= SRER_TXDATA;
2328         else if (tx >= 2)
2329                 sreron |= SRER_TXEMPTY;
2330         if (rx == 0)
2331                 sreroff |= SRER_RXDATA;
2332         else if (rx > 0)
2333                 sreron |= SRER_RXDATA;
2334 
2335         save_flags(flags);
2336         cli();
2337         BRDENABLE(portp->brdnr, portp->pagenr);
2338         stl_setreg(portp, CAR, (portp->portnr & 0x03));
2339         stl_setreg(portp, SRER, ((stl_getreg(portp, SRER) & ~sreroff) | sreron));
2340         BRDDISABLE(portp->brdnr);
2341         if (tx > 0)
2342                 set_bit(ASYI_TXBUSY, &portp->istate);
2343         restore_flags(flags);
2344 }
2345 
2346 /*****************************************************************************/
2347 
2348 /*
2349  *      Disable all interrupts from this port.
2350  */
2351 
2352 static void stl_disableintrs(stlport_t *portp)
     /* [previous][next][first][last][top][bottom][index][help] */
2353 {
2354         unsigned long   flags;
2355 
2356 #if DEBUG
2357         printk("stl_disableintrs(portp=%x)\n", (int) portp);
2358 #endif
2359         save_flags(flags);
2360         cli();
2361         BRDENABLE(portp->brdnr, portp->pagenr);
2362         stl_setreg(portp, CAR, (portp->portnr & 0x03));
2363         stl_setreg(portp, SRER, 0);
2364         BRDDISABLE(portp->brdnr);
2365         restore_flags(flags);
2366 }
2367 
2368 /*****************************************************************************/
2369 
2370 static void stl_sendbreak(stlport_t *portp, long len)
     /* [previous][next][first][last][top][bottom][index][help] */
2371 {
2372         unsigned long   flags;
2373 
2374 #if DEBUG
2375         printk("stl_sendbreak(portp=%x,len=%d)\n", (int) portp, (int) len);
2376 #endif
2377 
2378         save_flags(flags);
2379         cli();
2380         BRDENABLE(portp->brdnr, portp->pagenr);
2381         stl_setreg(portp, CAR, (portp->portnr & 0x03));
2382         stl_setreg(portp, COR2, (stl_getreg(portp, COR2) | COR2_ETC));
2383         stl_setreg(portp, SRER, ((stl_getreg(portp, SRER) & ~SRER_TXDATA) | SRER_TXEMPTY));
2384         BRDDISABLE(portp->brdnr);
2385         len = len / 5;
2386         portp->brklen = (len > 255) ? 255 : len;
2387         restore_flags(flags);
2388 }
2389 
2390 /*****************************************************************************/
2391 
2392 /*
2393  *      Map in interrupt vector to this driver. Check that we don't
2394  *      already have this vector mapped, we might be sharing this
2395  *      interrupt accross multiple boards.
2396  */
2397 
2398 static int stl_mapirq(int irq)
     /* [previous][next][first][last][top][bottom][index][help] */
2399 {
2400         int     rc, i;
2401 
2402 #if DEBUG
2403         printk("stl_mapirq(irq=%d)\n", irq);
2404 #endif
2405 
2406         rc = 0;
2407         for (i = 0; (i < stl_numintrs); i++) {
2408                 if (stl_gotintrs[i] == irq)
2409                         break;
2410         }
2411         if (i >= stl_numintrs) {
2412                 if (request_irq(irq, stl_intr, SA_INTERRUPT, stl_drvname) != 0) {
2413                         printk("STALLION: failed to register interrupt routine for irq=%d\n", irq);
2414                         rc = -ENODEV;
2415                 } else {
2416                         stl_gotintrs[stl_numintrs++] = irq;
2417                 }
2418         }
2419         return(rc);
2420 }
2421 
2422 /*****************************************************************************/
2423 
2424 /*
2425  *      Try and find and initialize all the ports on a panel. We don't care
2426  *      what sort of board these ports are on - since the port io registers
2427  *      are almost identical when dealing with ports.
2428  */
2429 
2430 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
     /* [previous][next][first][last][top][bottom][index][help] */
2431 {
2432         stlport_t       *portp;
2433         unsigned int    chipmask;
2434         unsigned int    gfrcr;
2435         int             nrchips, uartaddr, ioaddr;
2436         int             i, j;
2437 
2438 #if DEBUG
2439         printk("stl_initports(panelp=%x)\n", (int) panelp);
2440 #endif
2441 
2442         BRDENABLE(panelp->brdnr, panelp->pagenr);
2443 
2444 /*
2445  *      Check that each chip is present and started up OK.
2446  */
2447         chipmask = 0;
2448         nrchips = panelp->nrports / CD1400_PORTS;
2449         for (i = 0; (i < nrchips); i++) {
2450                 if (brdp->brdtype == BRD_ECHPCI) {
2451                         outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
2452                         ioaddr = panelp->iobase;
2453                 } else {
2454                         ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
2455                 }
2456                 uartaddr = (i & 0x01) ? 0x080 : 0;
2457                 outb((GFRCR + uartaddr), ioaddr);
2458                 outb(0, (ioaddr + EREG_DATA));
2459                 outb((CCR + uartaddr), ioaddr);
2460                 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
2461                 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
2462                 outb((GFRCR + uartaddr), ioaddr);
2463                 for (j = 0; (j < CCR_MAXWAIT); j++) {
2464                         if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
2465                                 break;
2466                 }
2467                 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
2468                         printk("STALLION: cd1400 not responding, brd=%d panel=%d chip=%d\n", panelp->brdnr, panelp->panelnr, i);
2469                         continue;
2470                 }
2471                 chipmask |= (0x1 << i);
2472                 outb((PPR + uartaddr), ioaddr);
2473                 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
2474         }
2475 
2476 /*
2477  *      All cd1400's are initialized (if found!). Now go through and setup
2478  *      each ports data structures. Also init the LIVR register of cd1400
2479  *      for each port.
2480  */
2481         ioaddr = panelp->iobase;
2482         for (i = 0; (i < panelp->nrports); i++) {
2483                 if (brdp->brdtype == BRD_ECHPCI) {
2484                         outb((panelp->pagenr + (i >> 3)), brdp->ioctrl);
2485                         ioaddr = panelp->iobase;
2486                 } else {
2487                         ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 3));
2488                 }
2489                 if ((chipmask & (0x1 << (i / 4))) == 0)
2490                         continue;
2491                 portp = (stlport_t *) stl_memalloc(sizeof(stlport_t));
2492                 if (portp == (stlport_t *) NULL) {
2493                         printk("STALLION: failed to allocate memory (size=%d)\n", sizeof(stlport_t));
2494                         break;
2495                 }
2496                 memset(portp, 0, sizeof(stlport_t));
2497                 portp->portnr = i;
2498                 portp->brdnr = panelp->brdnr;
2499                 portp->panelnr = panelp->panelnr;
2500                 portp->ioaddr = ioaddr;
2501                 portp->uartaddr = (i & 0x04) << 5;
2502                 portp->pagenr = panelp->pagenr + (i >> 3);
2503                 portp->baud_base = STL_BAUDBASE;
2504                 portp->close_delay = STL_CLOSEDELAY;
2505                 portp->closing_wait = 30 * HZ;
2506                 portp->normaltermios = stl_deftermios;
2507                 portp->callouttermios = stl_deftermios;
2508                 portp->tqueue.routine = stl_offintr;
2509                 portp->tqueue.data = portp;
2510                 stl_setreg(portp, CAR, (i & 0x03));
2511                 stl_setreg(portp, LIVR, (i << 3));
2512                 panelp->ports[i] = portp;
2513         }
2514 
2515         BRDDISABLE(panelp->brdnr);
2516         return(0);
2517 }
2518 
2519 /*****************************************************************************/
2520 
2521 /*
2522  *      Try to find and initialize an EasyIO board.
2523  */
2524 
2525 static int stl_initeio(stlbrd_t *brdp)
     /* [previous][next][first][last][top][bottom][index][help] */
2526 {
2527         stlpanel_t      *panelp;
2528         unsigned int    status;
2529         int             rc;
2530 
2531 #if DEBUG
2532         printk("stl_initeio(brdp=%x)\n", (int) brdp);
2533 #endif
2534 
2535         brdp->ioctrl = brdp->ioaddr1 + 1;
2536         brdp->iostatus = brdp->ioaddr1 + 2;
2537 
2538         status = inb(brdp->iostatus);
2539         switch (status & EIO_IDBITMASK) {
2540         case EIO_8PORTRS:
2541         case EIO_8PORTM:
2542         case EIO_8PORTDI:
2543                 brdp->nrports = 8;
2544                 break;
2545         case EIO_4PORTRS:
2546                 brdp->nrports = 4;
2547                 break;
2548         default:
2549                 return(-ENODEV);
2550         }
2551 
2552         request_region(brdp->ioaddr1, 8, "serial(EIO)");
2553 
2554 /*
2555  *      Check that the supplied IRQ is good and then use it to setup the
2556  *      programmable interrupt bits on EIO board. Also set the edge/level
2557  *      triggered interrupt bit.
2558  */
2559         if ((brdp->irq < 0) || (brdp->irq > 15) ||
2560                         (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2561                 printk("STALLION: invalid irq=%d for brd=%d\n", brdp->irq, brdp->brdnr);
2562                 return(-EINVAL);
2563         }
2564         outb((stl_vecmap[brdp->irq] | ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)), brdp->ioctrl);
2565 
2566         panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
2567         if (panelp == (stlpanel_t *) NULL) {
2568                 printk("STALLION: failed to allocate memory (size=%d)\n", sizeof(stlpanel_t));
2569                 return(-ENOMEM);
2570         }
2571         memset(panelp, 0, sizeof(stlpanel_t));
2572 
2573         panelp->brdnr = brdp->brdnr;
2574         panelp->panelnr = 0;
2575         panelp->nrports = brdp->nrports;
2576         panelp->iobase = brdp->ioaddr1;
2577         brdp->panels[0] = panelp;
2578         brdp->nrpanels = 1;
2579         brdp->state |= BRD_FOUND;
2580         rc = stl_mapirq(brdp->irq);
2581         return(rc);
2582 }
2583 
2584 /*****************************************************************************/
2585 
2586 /*
2587  *      Try to find an ECH board and initialize it. This code is capable of
2588  *      dealing with all types of ECH board.
2589  */
2590 
2591 static int stl_initech(stlbrd_t *brdp)
     /* [previous][next][first][last][top][bottom][index][help] */
2592 {
2593         stlpanel_t      *panelp;
2594         unsigned int    status, nxtid;
2595         int             panelnr, ioaddr, i;
2596 
2597 #if DEBUG
2598         printk("stl_initech(brdp=%x)\n", (int) brdp);
2599 #endif
2600 
2601 /*
2602  *      Set up the initial board register contents for boards. This varys a
2603  *      bit between the different board types. So we need to handle each
2604  *      separately. Also do a check that the supplied IRQ is good.
2605  */
2606         if (brdp->brdtype == BRD_ECH) {
2607                 brdp->ioctrl = brdp->ioaddr1 + 1;
2608                 brdp->iostatus = brdp->ioaddr1 + 1;
2609                 status = inb(brdp->iostatus);
2610                 if ((status & ECH_IDBITMASK) != ECH_ID)
2611                         return(-ENODEV);
2612 
2613                 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2614                                 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2615                         printk("STALLION: invalid irq=%d for brd=%d\n", brdp->irq, brdp->brdnr);
2616                         return(-EINVAL);
2617                 }
2618                 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2619                 status |= (stl_vecmap[brdp->irq] << 1);
2620                 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2621                 brdp->ioctrlval = ECH_INTENABLE | ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2622                 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2623                 outb(status, brdp->ioaddr1);
2624 
2625                 request_region(brdp->ioaddr1, 2, "serial(EC8/32)");
2626                 request_region(brdp->ioaddr2, 32, "serial(EC8/32-secondary)");
2627         } else if (brdp->brdtype == BRD_ECHMC) {
2628                 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2629                 brdp->iostatus = brdp->ioctrl;
2630                 status = inb(brdp->iostatus);
2631                 if ((status & ECH_IDBITMASK) != ECH_ID)
2632                         return(-ENODEV);
2633 
2634                 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2635                                 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2636                         printk("STALLION: invalid irq=%d for brd=%d\n", brdp->irq, brdp->brdnr);
2637                         return(-EINVAL);
2638                 }
2639                 outb(ECHMC_BRDRESET, brdp->ioctrl);
2640                 outb(ECHMC_INTENABLE, brdp->ioctrl);
2641 
2642                 request_region(brdp->ioaddr1, 64, "serial(EC8/32-MC)");
2643         } else if (brdp->brdtype == BRD_ECHPCI) {
2644                 brdp->ioctrl = brdp->ioaddr1 + 2;
2645                 request_region(brdp->ioaddr1, 4, "serial(EC8/32-PCI)");
2646                 request_region(brdp->ioaddr2, 8, "serial(EC8/32-PCI-secondary)");
2647         }
2648 
2649 /*
2650  *      Scan through the secondary io address space looking for panels.
2651  *      As we find'em allocate and initialize panel structures for each.
2652  */
2653         ioaddr = brdp->ioaddr2;
2654         panelnr = 0;
2655         nxtid = 0;
2656 
2657         for (i = 0; (i < STL_MAXPANELS); i++) {
2658                 if (brdp->brdtype == BRD_ECHPCI) {
2659                         outb(nxtid, brdp->ioctrl);
2660                         ioaddr = brdp->ioaddr2;
2661                 }
2662                 status = inb(ioaddr + ECH_PNLSTATUS);
2663                 if ((status & ECH_PNLIDMASK) != nxtid)
2664                         break;
2665                 panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
2666                 if (panelp == (stlpanel_t *) NULL) {
2667                         printk("STALLION: failed to allocate memory (size=%d)\n", sizeof(stlpanel_t));
2668                         break;
2669                 }
2670                 memset(panelp, 0, sizeof(stlpanel_t));
2671                 panelp->brdnr = brdp->brdnr;
2672                 panelp->panelnr = panelnr;
2673                 panelp->iobase = ioaddr;
2674                 panelp->pagenr = nxtid;
2675                 if (status & ECH_PNL16PORT) {
2676                         if ((brdp->nrports + 16) > 32)
2677                                 break;
2678                         panelp->nrports = 16;
2679                         panelp->ackmask = 0x80;
2680                         brdp->nrports += 16;
2681                         ioaddr += (EREG_BANKSIZE * 2);
2682                         nxtid += 2;
2683                 } else {
2684                         panelp->nrports = 8;
2685                         panelp->ackmask = 0xc0;
2686                         brdp->nrports += 8;
2687                         ioaddr += EREG_BANKSIZE;
2688                         nxtid++;
2689                 }
2690                 brdp->panels[panelnr++] = panelp;
2691                 brdp->nrpanels++;
2692                 if (ioaddr >= (brdp->ioaddr2 + 0x20))
2693                         break;
2694         }
2695 
2696         if (brdp->brdtype == BRD_ECH)
2697                 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2698 
2699         brdp->state |= BRD_FOUND;
2700         i = stl_mapirq(brdp->irq);
2701         return(i);
2702 }
2703 
2704 /*****************************************************************************/
2705 
2706 /*
2707  *      Initialize and configure the specified board.
2708  *      Scan through all the boards in the configuration and see what we
2709  *      can find. Handle EIO and the ECH boards a little differently here
2710  *      since the initial search and setup is too different.
2711  */
2712 
2713 static int stl_brdinit(stlbrd_t *brdp)
     /* [previous][next][first][last][top][bottom][index][help] */
2714 {
2715         int     i;
2716 
2717 #if DEBUG
2718         printk("stl_brdinit(brdp=%x)\n", (int) brdp);
2719 #endif
2720 
2721         switch (brdp->brdtype) {
2722         case BRD_EASYIO:
2723                 stl_initeio(brdp);
2724                 break;
2725         case BRD_ECH:
2726         case BRD_ECHMC:
2727         case BRD_ECHPCI:
2728                 stl_initech(brdp);
2729                 break;
2730         default:
2731                 printk("STALLION: unit=%d is unknown board type=%d\n", brdp->brdnr, brdp->brdtype);
2732                 return(ENODEV);
2733         }
2734 
2735         stl_brds[brdp->brdnr] = brdp;
2736         if ((brdp->state & BRD_FOUND) == 0) {
2737                 printk("STALLION: %s board not found, unit=%d io=%x irq=%d\n", stl_brdnames[brdp->brdtype], brdp->brdnr, brdp->ioaddr1, brdp->irq);
2738                 return(ENODEV);
2739         }
2740 
2741         for (i = 0; (i < STL_MAXPANELS); i++)
2742                 if (brdp->panels[i] != (stlpanel_t *) NULL)
2743                         stl_initports(brdp, brdp->panels[i]);
2744 
2745         printk("STALLION: %s found, unit=%d io=%x irq=%d nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype], brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels, brdp->nrports);
2746         return(0);
2747 }
2748 
2749 /*****************************************************************************/
2750 
2751 /*
2752  *      Find any ECH-PCI boards that might be installed. Initialize each
2753  *      one as it is found.
2754  */
2755 
2756 #ifdef  CONFIG_PCI
2757 
2758 static int stl_findpcibrds()
     /* [previous][next][first][last][top][bottom][index][help] */
2759 {
2760         stlbrd_t        *brdp;
2761         unsigned char   busnr, devnr, irq;
2762         unsigned short  class;
2763         unsigned int    ioaddr;
2764         int             i, rc;
2765 
2766 #if DEBUG
2767         printk("stl_findpcibrds()\n");
2768 #endif
2769 
2770         if (pcibios_present()) {
2771                 for (i = 0; (i < STL_MAXBRDS); i++) {
2772                         if (pcibios_find_device(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, i, &busnr, &devnr))
2773                                 break;
2774 
2775 /*
2776  *                      Found a device on the PCI bus that has our vendor and
2777  *                      device ID. Need to check now that it is really us.
2778  */
2779                         if ((rc = pcibios_read_config_word(busnr, devnr, PCI_CLASS_DEVICE, &class))) {
2780                                 printk("STALLION: failed to read class type from PCI board, errno=%x\n", rc);
2781                                 continue;
2782                         }
2783                         if (class == PCI_CLASS_STORAGE_IDE)
2784                                 continue;
2785 
2786                         if (stl_nrbrds >= STL_MAXBRDS) {
2787                                 printk("STALLION: too many boards found, maximum supported %d\n", STL_MAXBRDS);
2788                                 break;
2789                         }
2790 
2791 /*
2792  *                      We have a Stallion board. Allocate a board structure
2793  *                      and initialize it. Read its IO and IRQ resources
2794  *                      from conf space.
2795  */
2796                         brdp = (stlbrd_t *) stl_memalloc(sizeof(stlbrd_t));
2797                         if (brdp == (stlbrd_t *) NULL) {
2798                                 printk("STALLION: failed to allocate memory (size=%d)\n", sizeof(stlbrd_t));
2799                                 return(-ENOMEM);
2800                         }
2801                         memset(brdp, 0, sizeof(stlbrd_t));
2802                         brdp->brdnr = stl_nrbrds++;
2803                         brdp->brdtype = BRD_ECHPCI;
2804 
2805                         if ((rc = pcibios_read_config_dword(busnr, devnr, PCI_BASE_ADDRESS_0, &ioaddr))) {
2806                                 printk("STALLION: failed to read BAR register from PCI board, errno=%x\n", rc);
2807                                 continue;
2808                         }
2809                         brdp->ioaddr2 = (ioaddr & PCI_BASE_ADDRESS_IO_MASK);
2810 
2811                         if ((rc = pcibios_read_config_dword(busnr, devnr, PCI_BASE_ADDRESS_1, &ioaddr))) {
2812                                 printk("STALLION: failed to read BAR register from PCI board, errno=%x\n", rc);
2813                                 continue;
2814                         }
2815                         brdp->ioaddr1 = (ioaddr & PCI_BASE_ADDRESS_IO_MASK);
2816 #if DEBUG
2817                         printk("%s(%d): BAR0=%x BAR1=%x\n", __FILE__, __LINE__, brdp->ioaddr2, brdp->ioaddr1);
2818 #endif
2819 
2820                         if ((rc = pcibios_read_config_byte(busnr, devnr, PCI_INTERRUPT_LINE, &irq))) {
2821                                 printk("STALLION: failed to read BAR register from PCI board, errno=%x\n", rc);
2822                                 continue;
2823                         }
2824                         brdp->irq = irq;
2825 
2826 #if 0
2827                         ioaddr = 0x0c000001;
2828                         if ((rc = pcibios_write_config_dword(busnr, devnr, 0x40, ioaddr))) {
2829                                 printk("STALLION: failed to write register on PCI board, errno=%x\n", rc);
2830                                 continue;
2831                         }
2832                         if ((rc = pcibios_write_config_dword(busnr, devnr, 0x48, ioaddr))) {
2833                                 printk("STALLION: failed to write register on PCI board, errno=%x\n", rc);
2834                                 continue;
2835                         }
2836 #endif
2837 
2838                         stl_brdinit(brdp);
2839                 }
2840         }
2841 
2842         return(0);
2843 }
2844 
2845 #endif
2846 
2847 /*****************************************************************************/
2848 
2849 /*
2850  *      Scan through all the boards in the configuration and see what we
2851  *      can find. Handle EIO and the ECH boards a little differently here
2852  *      since the initial search and setup is too different.
2853  */
2854 
2855 static int stl_initbrds()
     /* [previous][next][first][last][top][bottom][index][help] */
2856 {
2857         stlbrd_t        *brdp;
2858         stlconf_t       *confp;
2859         int             i;
2860 
2861 #if DEBUG
2862         printk("stl_initbrds()\n");
2863 #endif
2864 
2865         if (stl_nrbrds > STL_MAXBRDS) {
2866                 printk("STALLION: too many boards in configuration table, truncating to %d\n", STL_MAXBRDS);
2867                 stl_nrbrds = STL_MAXBRDS;
2868         }
2869 
2870 /*
2871  *      Firstly scan the list of static boards configured. Allocate
2872  *      resources and initialize the boards as found.
2873  */
2874         for (i = 0; (i < stl_nrbrds); i++) {
2875                 confp = &stl_brdconf[i];
2876                 brdp = (stlbrd_t *) stl_memalloc(sizeof(stlbrd_t));
2877                 if (brdp == (stlbrd_t *) NULL) {
2878                         printk("STALLION: failed to allocate memory (size=%d)\n", sizeof(stlbrd_t));
2879                         return(-ENOMEM);
2880                 }
2881                 memset(brdp, 0, sizeof(stlbrd_t));
2882 
2883                 brdp->brdnr = i;
2884                 brdp->brdtype = confp->brdtype;
2885                 brdp->ioaddr1 = confp->ioaddr1;
2886                 brdp->ioaddr2 = confp->ioaddr2;
2887                 brdp->irq = confp->irq;
2888                 brdp->irqtype = confp->irqtype;
2889                 stl_brdinit(brdp);
2890         }
2891 
2892 #ifdef CONFIG_PCI
2893 /*
2894  *      If the PCI BIOS support is compiled in then lets go looking for
2895  *      ECH-PCI boards.
2896  */
2897         stl_findpcibrds();
2898 #endif
2899 
2900         return(0);
2901 }
2902 
2903 /*****************************************************************************/
2904 
2905 long stl_init(long kmem_start)
     /* [previous][next][first][last][top][bottom][index][help] */
2906 {
2907         printk("%s: version %s\n", stl_drvname, stl_drvversion);
2908 
2909 #ifndef MODULE
2910         stl_meminit(kmem_start);
2911 #endif
2912 
2913         stl_initbrds();
2914 
2915 /*
2916  *      Allocate a temporary write buffer.
2917  */
2918         stl_tmpwritebuf = (char *) stl_memalloc(STL_TXBUFSIZE);
2919         if (stl_tmpwritebuf == (char *) NULL)
2920                 printk("STALLION: failed to allocate memory (size=%d)\n", STL_TXBUFSIZE);
2921 
2922 /*
2923  *      Set up the tty driver structure and register us as a driver.
2924  *      Also setup the callout tty device.
2925  */
2926         memset(&stl_serial, 0, sizeof(struct tty_driver));
2927         stl_serial.magic = TTY_DRIVER_MAGIC;
2928         stl_serial.name = stl_serialname;
2929         stl_serial.major = STL_SERIALMAJOR;
2930         stl_serial.minor_start = 0;
2931         stl_serial.num = STL_MAXBRDS * STL_MAXPORTS;
2932         stl_serial.type = TTY_DRIVER_TYPE_SERIAL;
2933         stl_serial.subtype = STL_DRVTYPSERIAL;
2934         stl_serial.init_termios = stl_deftermios;
2935         stl_serial.flags = TTY_DRIVER_REAL_RAW;
2936         stl_serial.refcount = &stl_refcount;
2937         stl_serial.table = stl_ttys;
2938         stl_serial.termios = stl_termios;
2939         stl_serial.termios_locked = stl_termioslocked;
2940         
2941         stl_serial.open = stl_open;
2942         stl_serial.close = stl_close;
2943         stl_serial.write = stl_write;
2944         stl_serial.put_char = stl_putchar;
2945         stl_serial.flush_chars = stl_flushchars;
2946         stl_serial.write_room = stl_writeroom;
2947         stl_serial.chars_in_buffer = stl_charsinbuffer;
2948         stl_serial.ioctl = stl_ioctl;
2949         stl_serial.set_termios = stl_settermios;
2950         stl_serial.throttle = stl_throttle;
2951         stl_serial.unthrottle = stl_unthrottle;
2952         stl_serial.stop = stl_stop;
2953         stl_serial.start = stl_start;
2954         stl_serial.hangup = stl_hangup;
2955         stl_serial.flush_buffer = stl_flushbuffer;
2956 
2957         stl_callout = stl_serial;
2958         stl_callout.name = stl_calloutname;
2959         stl_callout.major = STL_CALLOUTMAJOR;
2960         stl_callout.subtype = STL_DRVTYPCALLOUT;
2961 
2962         if (tty_register_driver(&stl_serial))
2963                 printk("STALLION: failed to register serial driver\n");
2964         if (tty_register_driver(&stl_callout))
2965                 printk("STALLION: failed to register callout driver\n");
2966 
2967 #ifndef MODULE
2968         kmem_start = stl_memhalt();
2969 #endif
2970         return(kmem_start);
2971 }
2972 
2973 /*****************************************************************************/

/* [previous][next][first][last][top][bottom][index][help] */