1 /*****************************************************************************/
4 * stallion.c -- stallion multiport serial driver.
6 * Copyright (C) 1996-1999 Stallion Technologies
7 * Copyright (C) 1994-1996 Greg Ungerer.
9 * This code is loosely based on the Linux serial driver, written by
10 * Linus Torvalds, Theodore T'so and others.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /*****************************************************************************/
29 #include <linux/module.h>
30 #include <linux/slab.h>
31 #include <linux/interrupt.h>
32 #include <linux/tty.h>
33 #include <linux/tty_flip.h>
34 #include <linux/serial.h>
35 #include <linux/cd1400.h>
36 #include <linux/sc26198.h>
37 #include <linux/comstats.h>
38 #include <linux/stallion.h>
39 #include <linux/ioport.h>
40 #include <linux/init.h>
41 #include <linux/smp_lock.h>
42 #include <linux/device.h>
43 #include <linux/delay.h>
46 #include <asm/uaccess.h>
49 #include <linux/pci.h>
52 /*****************************************************************************/
55 * Define different board types. Use the standard Stallion "assigned"
56 * board numbers. Boards supported in this driver are abbreviated as
57 * EIO = EasyIO and ECH = EasyConnection 8/32.
63 #define BRD_ECH64PCI 27
64 #define BRD_EASYIOPCI 28
67 * Define a configuration structure to hold the board configuration.
68 * Need to set this up in the code (for now) with the boards that are
69 * to be configured into the system. This is what needs to be modified
70 * when adding/removing/modifying boards. Each line entry in the
71 * stl_brdconf[] array is a board. Each line contains io/irq/memory
72 * ranges for that board (as well as what type of board it is).
74 * { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
75 * This line would configure an EasyIO board (4 or 8, no difference),
76 * at io address 2a0 and irq 10.
78 * { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
79 * This line will configure an EasyConnection 8/32 board at primary io
80 * address 2a8, secondary io address 280 and irq 12.
81 * Enter as many lines into this array as you want (only the first 4
82 * will actually be used!). Any combination of EasyIO and EasyConnection
83 * boards can be specified. EasyConnection 8/32 boards can share their
84 * secondary io addresses between each other.
86 * NOTE: there is no need to put any entries in this table for PCI
87 * boards. They will be found automatically by the driver - provided
88 * PCI BIOS32 support is compiled into the kernel.
91 static struct stlconf {
95 unsigned long memaddr;
99 /*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
102 static int stl_nrbrds = ARRAY_SIZE(stl_brdconf);
104 /*****************************************************************************/
107 * Define some important driver characteristics. Device major numbers
108 * allocated as per Linux Device Registry.
110 #ifndef STL_SIOMEMMAJOR
111 #define STL_SIOMEMMAJOR 28
113 #ifndef STL_SERIALMAJOR
114 #define STL_SERIALMAJOR 24
116 #ifndef STL_CALLOUTMAJOR
117 #define STL_CALLOUTMAJOR 25
121 * Set the TX buffer size. Bigger is better, but we don't want
122 * to chew too much memory with buffers!
124 #define STL_TXBUFLOW 512
125 #define STL_TXBUFSIZE 4096
127 /*****************************************************************************/
130 * Define our local driver identity first. Set up stuff to deal with
131 * all the local structures required by a serial tty driver.
133 static char *stl_drvtitle = "Stallion Multiport Serial Driver";
134 static char *stl_drvname = "stallion";
135 static char *stl_drvversion = "5.6.0";
137 static struct tty_driver *stl_serial;
140 * Define a local default termios struct. All ports will be created
141 * with this termios initially. Basically all it defines is a raw port
142 * at 9600, 8 data bits, 1 stop bit.
144 static struct termios stl_deftermios = {
145 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
150 * Define global stats structures. Not used often, and can be
151 * re-used for each stats call.
153 static comstats_t stl_comstats;
154 static combrd_t stl_brdstats;
155 static struct stlbrd stl_dummybrd;
156 static struct stlport stl_dummyport;
159 * Define global place to put buffer overflow characters.
161 static char stl_unwanted[SC26198_RXFIFOSIZE];
163 /*****************************************************************************/
165 static struct stlbrd *stl_brds[STL_MAXBRDS];
168 * Per board state flags. Used with the state field of the board struct.
169 * Not really much here!
171 #define BRD_FOUND 0x1
174 * Define the port structure istate flags. These set of flags are
175 * modified at interrupt time - so setting and reseting them needs
176 * to be atomic. Use the bit clear/setting routines for this.
178 #define ASYI_TXBUSY 1
180 #define ASYI_DCDCHANGE 3
181 #define ASYI_TXFLOWED 4
184 * Define an array of board names as printable strings. Handy for
185 * referencing boards when printing trace and stuff.
187 static char *stl_brdnames[] = {
219 /*****************************************************************************/
222 * Define some string labels for arguments passed from the module
223 * load line. These allow for easy board definitions, and easy
224 * modification of the io, memory and irq resoucres.
226 static int stl_nargs = 0;
227 static char *board0[4];
228 static char *board1[4];
229 static char *board2[4];
230 static char *board3[4];
232 static char **stl_brdsp[] = {
240 * Define a set of common board names, and types. This is used to
241 * parse any module arguments.
248 { "easyio", BRD_EASYIO },
249 { "eio", BRD_EASYIO },
250 { "20", BRD_EASYIO },
251 { "ec8/32", BRD_ECH },
252 { "ec8/32-at", BRD_ECH },
253 { "ec8/32-isa", BRD_ECH },
255 { "echat", BRD_ECH },
257 { "ec8/32-mc", BRD_ECHMC },
258 { "ec8/32-mca", BRD_ECHMC },
259 { "echmc", BRD_ECHMC },
260 { "echmca", BRD_ECHMC },
262 { "ec8/32-pc", BRD_ECHPCI },
263 { "ec8/32-pci", BRD_ECHPCI },
264 { "26", BRD_ECHPCI },
265 { "ec8/64-pc", BRD_ECH64PCI },
266 { "ec8/64-pci", BRD_ECH64PCI },
267 { "ech-pci", BRD_ECH64PCI },
268 { "echpci", BRD_ECH64PCI },
269 { "echpc", BRD_ECH64PCI },
270 { "27", BRD_ECH64PCI },
271 { "easyio-pc", BRD_EASYIOPCI },
272 { "easyio-pci", BRD_EASYIOPCI },
273 { "eio-pci", BRD_EASYIOPCI },
274 { "eiopci", BRD_EASYIOPCI },
275 { "28", BRD_EASYIOPCI },
279 * Define the module agruments.
282 module_param_array(board0, charp, &stl_nargs, 0);
283 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
284 module_param_array(board1, charp, &stl_nargs, 0);
285 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
286 module_param_array(board2, charp, &stl_nargs, 0);
287 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
288 module_param_array(board3, charp, &stl_nargs, 0);
289 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
291 /*****************************************************************************/
294 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
295 * to the directly accessible io ports of these boards (not the uarts -
296 * they are in cd1400.h and sc26198.h).
298 #define EIO_8PORTRS 0x04
299 #define EIO_4PORTRS 0x05
300 #define EIO_8PORTDI 0x00
301 #define EIO_8PORTM 0x06
303 #define EIO_IDBITMASK 0x07
305 #define EIO_BRDMASK 0xf0
308 #define ID_BRD16 0x30
310 #define EIO_INTRPEND 0x08
311 #define EIO_INTEDGE 0x00
312 #define EIO_INTLEVEL 0x08
316 #define ECH_IDBITMASK 0xe0
317 #define ECH_BRDENABLE 0x08
318 #define ECH_BRDDISABLE 0x00
319 #define ECH_INTENABLE 0x01
320 #define ECH_INTDISABLE 0x00
321 #define ECH_INTLEVEL 0x02
322 #define ECH_INTEDGE 0x00
323 #define ECH_INTRPEND 0x01
324 #define ECH_BRDRESET 0x01
326 #define ECHMC_INTENABLE 0x01
327 #define ECHMC_BRDRESET 0x02
329 #define ECH_PNLSTATUS 2
330 #define ECH_PNL16PORT 0x20
331 #define ECH_PNLIDMASK 0x07
332 #define ECH_PNLXPID 0x40
333 #define ECH_PNLINTRPEND 0x80
335 #define ECH_ADDR2MASK 0x1e0
338 * Define the vector mapping bits for the programmable interrupt board
339 * hardware. These bits encode the interrupt for the board to use - it
340 * is software selectable (except the EIO-8M).
342 static unsigned char stl_vecmap[] = {
343 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
344 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
348 * Lock ordering is that you may not take stallion_lock holding
352 static spinlock_t brd_lock; /* Guard the board mapping */
353 static spinlock_t stallion_lock; /* Guard the tty driver */
356 * Set up enable and disable macros for the ECH boards. They require
357 * the secondary io address space to be activated and deactivated.
358 * This way all ECH boards can share their secondary io region.
359 * If this is an ECH-PCI board then also need to set the page pointer
360 * to point to the correct page.
362 #define BRDENABLE(brdnr,pagenr) \
363 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
364 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
365 stl_brds[(brdnr)]->ioctrl); \
366 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
367 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
369 #define BRDDISABLE(brdnr) \
370 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
371 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
372 stl_brds[(brdnr)]->ioctrl);
374 #define STL_CD1400MAXBAUD 230400
375 #define STL_SC26198MAXBAUD 460800
377 #define STL_BAUDBASE 115200
378 #define STL_CLOSEDELAY (5 * HZ / 10)
380 /*****************************************************************************/
385 * Define the Stallion PCI vendor and device IDs.
387 #ifndef PCI_VENDOR_ID_STALLION
388 #define PCI_VENDOR_ID_STALLION 0x124d
390 #ifndef PCI_DEVICE_ID_ECHPCI832
391 #define PCI_DEVICE_ID_ECHPCI832 0x0000
393 #ifndef PCI_DEVICE_ID_ECHPCI864
394 #define PCI_DEVICE_ID_ECHPCI864 0x0002
396 #ifndef PCI_DEVICE_ID_EIOPCI
397 #define PCI_DEVICE_ID_EIOPCI 0x0003
401 * Define structure to hold all Stallion PCI boards.
403 typedef struct stlpcibrd {
404 unsigned short vendid;
405 unsigned short devid;
409 static stlpcibrd_t stl_pcibrds[] = {
410 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864, BRD_ECH64PCI },
411 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI, BRD_EASYIOPCI },
412 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832, BRD_ECHPCI },
413 { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
416 static int stl_nrpcibrds = ARRAY_SIZE(stl_pcibrds);
420 /*****************************************************************************/
423 * Define macros to extract a brd/port number from a minor number.
425 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
426 #define MINOR2PORT(min) ((min) & 0x3f)
429 * Define a baud rate table that converts termios baud rate selector
430 * into the actual baud rate value. All baud rate calculations are
431 * based on the actual baud rate required.
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, 460800, 921600
439 * Define some handy local macros...
442 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
445 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
447 /*****************************************************************************/
450 * Declare all those functions in this driver!
453 static void stl_argbrds(void);
454 static int stl_parsebrd(struct stlconf *confp, char **argp);
456 static unsigned long stl_atol(char *str);
458 static int stl_open(struct tty_struct *tty, struct file *filp);
459 static void stl_close(struct tty_struct *tty, struct file *filp);
460 static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count);
461 static void stl_putchar(struct tty_struct *tty, unsigned char ch);
462 static void stl_flushchars(struct tty_struct *tty);
463 static int stl_writeroom(struct tty_struct *tty);
464 static int stl_charsinbuffer(struct tty_struct *tty);
465 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
466 static void stl_settermios(struct tty_struct *tty, struct termios *old);
467 static void stl_throttle(struct tty_struct *tty);
468 static void stl_unthrottle(struct tty_struct *tty);
469 static void stl_stop(struct tty_struct *tty);
470 static void stl_start(struct tty_struct *tty);
471 static void stl_flushbuffer(struct tty_struct *tty);
472 static void stl_breakctl(struct tty_struct *tty, int state);
473 static void stl_waituntilsent(struct tty_struct *tty, int timeout);
474 static void stl_sendxchar(struct tty_struct *tty, char ch);
475 static void stl_hangup(struct tty_struct *tty);
476 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
477 static int stl_portinfo(struct stlport *portp, int portnr, char *pos);
478 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data);
480 static int stl_brdinit(struct stlbrd *brdp);
481 static int stl_initports(struct stlbrd *brdp, struct stlpanel *panelp);
482 static int stl_getserial(struct stlport *portp, struct serial_struct __user *sp);
483 static int stl_setserial(struct stlport *portp, struct serial_struct __user *sp);
484 static int stl_getbrdstats(combrd_t __user *bp);
485 static int stl_getportstats(struct stlport *portp, comstats_t __user *cp);
486 static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp);
487 static int stl_getportstruct(struct stlport __user *arg);
488 static int stl_getbrdstruct(struct stlbrd __user *arg);
489 static int stl_waitcarrier(struct stlport *portp, struct file *filp);
490 static int stl_eiointr(struct stlbrd *brdp);
491 static int stl_echatintr(struct stlbrd *brdp);
492 static int stl_echmcaintr(struct stlbrd *brdp);
493 static int stl_echpciintr(struct stlbrd *brdp);
494 static int stl_echpci64intr(struct stlbrd *brdp);
495 static void stl_offintr(struct work_struct *);
496 static struct stlbrd *stl_allocbrd(void);
497 static struct stlport *stl_getport(int brdnr, int panelnr, int portnr);
499 static inline int stl_initbrds(void);
500 static inline int stl_initeio(struct stlbrd *brdp);
501 static inline int stl_initech(struct stlbrd *brdp);
502 static inline int stl_getbrdnr(void);
505 static inline int stl_findpcibrds(void);
506 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp);
510 * CD1400 uart specific handling functions.
512 static void stl_cd1400setreg(struct stlport *portp, int regnr, int value);
513 static int stl_cd1400getreg(struct stlport *portp, int regnr);
514 static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value);
515 static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
516 static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
517 static void stl_cd1400setport(struct stlport *portp, struct termios *tiosp);
518 static int stl_cd1400getsignals(struct stlport *portp);
519 static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts);
520 static void stl_cd1400ccrwait(struct stlport *portp);
521 static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx);
522 static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx);
523 static void stl_cd1400disableintrs(struct stlport *portp);
524 static void stl_cd1400sendbreak(struct stlport *portp, int len);
525 static void stl_cd1400flowctrl(struct stlport *portp, int state);
526 static void stl_cd1400sendflow(struct stlport *portp, int state);
527 static void stl_cd1400flush(struct stlport *portp);
528 static int stl_cd1400datastate(struct stlport *portp);
529 static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase);
530 static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase);
531 static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr);
532 static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr);
533 static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr);
535 static inline int stl_cd1400breakisr(struct stlport *portp, int ioaddr);
538 * SC26198 uart specific handling functions.
540 static void stl_sc26198setreg(struct stlport *portp, int regnr, int value);
541 static int stl_sc26198getreg(struct stlport *portp, int regnr);
542 static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value);
543 static int stl_sc26198getglobreg(struct stlport *portp, int regnr);
544 static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
545 static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
546 static void stl_sc26198setport(struct stlport *portp, struct termios *tiosp);
547 static int stl_sc26198getsignals(struct stlport *portp);
548 static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts);
549 static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx);
550 static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx);
551 static void stl_sc26198disableintrs(struct stlport *portp);
552 static void stl_sc26198sendbreak(struct stlport *portp, int len);
553 static void stl_sc26198flowctrl(struct stlport *portp, int state);
554 static void stl_sc26198sendflow(struct stlport *portp, int state);
555 static void stl_sc26198flush(struct stlport *portp);
556 static int stl_sc26198datastate(struct stlport *portp);
557 static void stl_sc26198wait(struct stlport *portp);
558 static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty);
559 static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase);
560 static void stl_sc26198txisr(struct stlport *port);
561 static void stl_sc26198rxisr(struct stlport *port, unsigned int iack);
562 static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch);
563 static void stl_sc26198rxbadchars(struct stlport *portp);
564 static void stl_sc26198otherisr(struct stlport *port, unsigned int iack);
566 /*****************************************************************************/
569 * Generic UART support structure.
571 typedef struct uart {
572 int (*panelinit)(struct stlbrd *brdp, struct stlpanel *panelp);
573 void (*portinit)(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
574 void (*setport)(struct stlport *portp, struct termios *tiosp);
575 int (*getsignals)(struct stlport *portp);
576 void (*setsignals)(struct stlport *portp, int dtr, int rts);
577 void (*enablerxtx)(struct stlport *portp, int rx, int tx);
578 void (*startrxtx)(struct stlport *portp, int rx, int tx);
579 void (*disableintrs)(struct stlport *portp);
580 void (*sendbreak)(struct stlport *portp, int len);
581 void (*flowctrl)(struct stlport *portp, int state);
582 void (*sendflow)(struct stlport *portp, int state);
583 void (*flush)(struct stlport *portp);
584 int (*datastate)(struct stlport *portp);
585 void (*intr)(struct stlpanel *panelp, unsigned int iobase);
589 * Define some macros to make calling these functions nice and clean.
591 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
592 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
593 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
594 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
595 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
596 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
597 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
598 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
599 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
600 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
601 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
602 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
603 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
605 /*****************************************************************************/
608 * CD1400 UART specific data initialization.
610 static uart_t stl_cd1400uart = {
614 stl_cd1400getsignals,
615 stl_cd1400setsignals,
616 stl_cd1400enablerxtx,
618 stl_cd1400disableintrs,
628 * Define the offsets within the register bank of a cd1400 based panel.
629 * These io address offsets are common to the EasyIO board as well.
637 #define EREG_BANKSIZE 8
639 #define CD1400_CLK 25000000
640 #define CD1400_CLK8M 20000000
643 * Define the cd1400 baud rate clocks. These are used when calculating
644 * what clock and divisor to use for the required baud rate. Also
645 * define the maximum baud rate allowed, and the default base baud.
647 static int stl_cd1400clkdivs[] = {
648 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
651 /*****************************************************************************/
654 * SC26198 UART specific data initization.
656 static uart_t stl_sc26198uart = {
657 stl_sc26198panelinit,
660 stl_sc26198getsignals,
661 stl_sc26198setsignals,
662 stl_sc26198enablerxtx,
663 stl_sc26198startrxtx,
664 stl_sc26198disableintrs,
665 stl_sc26198sendbreak,
669 stl_sc26198datastate,
674 * Define the offsets within the register bank of a sc26198 based panel.
682 #define XP_BANKSIZE 4
685 * Define the sc26198 baud rate table. Offsets within the table
686 * represent the actual baud rate selector of sc26198 registers.
688 static unsigned int sc26198_baudtable[] = {
689 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
690 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
691 230400, 460800, 921600
694 #define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
696 /*****************************************************************************/
699 * Define the driver info for a user level control device. Used mainly
700 * to get at port stats - only not using the port device itself.
702 static const struct file_operations stl_fsiomem = {
703 .owner = THIS_MODULE,
704 .ioctl = stl_memioctl,
707 static struct class *stallion_class;
710 * Check for any arguments passed in on the module load command line.
713 static void stl_argbrds(void)
719 pr_debug("stl_argbrds()\n");
721 for (i = stl_nrbrds; (i < stl_nargs); i++) {
722 memset(&conf, 0, sizeof(conf));
723 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
725 if ((brdp = stl_allocbrd()) == NULL)
729 brdp->brdtype = conf.brdtype;
730 brdp->ioaddr1 = conf.ioaddr1;
731 brdp->ioaddr2 = conf.ioaddr2;
732 brdp->irq = conf.irq;
733 brdp->irqtype = conf.irqtype;
738 /*****************************************************************************/
741 * Convert an ascii string number into an unsigned long.
744 static unsigned long stl_atol(char *str)
752 if ((*sp == '0') && (*(sp+1) == 'x')) {
755 } else if (*sp == '0') {
762 for (; (*sp != 0); sp++) {
763 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
764 if ((c < 0) || (c >= base)) {
765 printk("STALLION: invalid argument %s\n", str);
769 val = (val * base) + c;
774 /*****************************************************************************/
777 * Parse the supplied argument string, into the board conf struct.
780 static int stl_parsebrd(struct stlconf *confp, char **argp)
785 pr_debug("stl_parsebrd(confp=%p,argp=%p)\n", confp, argp);
787 if ((argp[0] == NULL) || (*argp[0] == 0))
790 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
793 for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++) {
794 if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
797 if (i == ARRAY_SIZE(stl_brdstr)) {
798 printk("STALLION: unknown board name, %s?\n", argp[0]);
802 confp->brdtype = stl_brdstr[i].type;
805 if ((argp[i] != NULL) && (*argp[i] != 0))
806 confp->ioaddr1 = stl_atol(argp[i]);
808 if (confp->brdtype == BRD_ECH) {
809 if ((argp[i] != NULL) && (*argp[i] != 0))
810 confp->ioaddr2 = stl_atol(argp[i]);
813 if ((argp[i] != NULL) && (*argp[i] != 0))
814 confp->irq = stl_atol(argp[i]);
818 /*****************************************************************************/
821 * Allocate a new board structure. Fill out the basic info in it.
824 static struct stlbrd *stl_allocbrd(void)
828 brdp = kzalloc(sizeof(struct stlbrd), GFP_KERNEL);
830 printk("STALLION: failed to allocate memory (size=%Zd)\n",
831 sizeof(struct stlbrd));
835 brdp->magic = STL_BOARDMAGIC;
839 /*****************************************************************************/
841 static int stl_open(struct tty_struct *tty, struct file *filp)
843 struct stlport *portp;
845 unsigned int minordev;
846 int brdnr, panelnr, portnr, rc;
848 pr_debug("stl_open(tty=%p,filp=%p): device=%s\n", tty, filp, tty->name);
850 minordev = tty->index;
851 brdnr = MINOR2BRD(minordev);
852 if (brdnr >= stl_nrbrds)
854 brdp = stl_brds[brdnr];
857 minordev = MINOR2PORT(minordev);
858 for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
859 if (brdp->panels[panelnr] == NULL)
861 if (minordev < brdp->panels[panelnr]->nrports) {
865 minordev -= brdp->panels[panelnr]->nrports;
870 portp = brdp->panels[panelnr]->ports[portnr];
875 * On the first open of the device setup the port hardware, and
876 * initialize the per port data structure.
879 tty->driver_data = portp;
882 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
883 if (!portp->tx.buf) {
884 portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
887 portp->tx.head = portp->tx.buf;
888 portp->tx.tail = portp->tx.buf;
890 stl_setport(portp, tty->termios);
891 portp->sigs = stl_getsignals(portp);
892 stl_setsignals(portp, 1, 1);
893 stl_enablerxtx(portp, 1, 1);
894 stl_startrxtx(portp, 1, 0);
895 clear_bit(TTY_IO_ERROR, &tty->flags);
896 portp->flags |= ASYNC_INITIALIZED;
900 * Check if this port is in the middle of closing. If so then wait
901 * until it is closed then return error status, based on flag settings.
902 * The sleep here does not need interrupt protection since the wakeup
903 * for it is done with the same context.
905 if (portp->flags & ASYNC_CLOSING) {
906 interruptible_sleep_on(&portp->close_wait);
907 if (portp->flags & ASYNC_HUP_NOTIFY)
913 * Based on type of open being done check if it can overlap with any
914 * previous opens still in effect. If we are a normal serial device
915 * then also we might have to wait for carrier.
917 if (!(filp->f_flags & O_NONBLOCK)) {
918 if ((rc = stl_waitcarrier(portp, filp)) != 0)
921 portp->flags |= ASYNC_NORMAL_ACTIVE;
926 /*****************************************************************************/
929 * Possibly need to wait for carrier (DCD signal) to come high. Say
930 * maybe because if we are clocal then we don't need to wait...
933 static int stl_waitcarrier(struct stlport *portp, struct file *filp)
938 pr_debug("stl_waitcarrier(portp=%p,filp=%p)\n", portp, filp);
943 spin_lock_irqsave(&stallion_lock, flags);
945 if (portp->tty->termios->c_cflag & CLOCAL)
948 portp->openwaitcnt++;
949 if (! tty_hung_up_p(filp))
953 /* Takes brd_lock internally */
954 stl_setsignals(portp, 1, 1);
955 if (tty_hung_up_p(filp) ||
956 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
957 if (portp->flags & ASYNC_HUP_NOTIFY)
963 if (((portp->flags & ASYNC_CLOSING) == 0) &&
964 (doclocal || (portp->sigs & TIOCM_CD))) {
967 if (signal_pending(current)) {
972 interruptible_sleep_on(&portp->open_wait);
975 if (! tty_hung_up_p(filp))
977 portp->openwaitcnt--;
978 spin_unlock_irqrestore(&stallion_lock, flags);
983 /*****************************************************************************/
985 static void stl_close(struct tty_struct *tty, struct file *filp)
987 struct stlport *portp;
990 pr_debug("stl_close(tty=%p,filp=%p)\n", tty, filp);
992 portp = tty->driver_data;
996 spin_lock_irqsave(&stallion_lock, flags);
997 if (tty_hung_up_p(filp)) {
998 spin_unlock_irqrestore(&stallion_lock, flags);
1001 if ((tty->count == 1) && (portp->refcount != 1))
1002 portp->refcount = 1;
1003 if (portp->refcount-- > 1) {
1004 spin_unlock_irqrestore(&stallion_lock, flags);
1008 portp->refcount = 0;
1009 portp->flags |= ASYNC_CLOSING;
1012 * May want to wait for any data to drain before closing. The BUSY
1013 * flag keeps track of whether we are still sending or not - it is
1014 * very accurate for the cd1400, not quite so for the sc26198.
1015 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1019 spin_unlock_irqrestore(&stallion_lock, flags);
1021 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1022 tty_wait_until_sent(tty, portp->closing_wait);
1023 stl_waituntilsent(tty, (HZ / 2));
1026 spin_lock_irqsave(&stallion_lock, flags);
1027 portp->flags &= ~ASYNC_INITIALIZED;
1028 spin_unlock_irqrestore(&stallion_lock, flags);
1030 stl_disableintrs(portp);
1031 if (tty->termios->c_cflag & HUPCL)
1032 stl_setsignals(portp, 0, 0);
1033 stl_enablerxtx(portp, 0, 0);
1034 stl_flushbuffer(tty);
1036 if (portp->tx.buf != NULL) {
1037 kfree(portp->tx.buf);
1038 portp->tx.buf = NULL;
1039 portp->tx.head = NULL;
1040 portp->tx.tail = NULL;
1042 set_bit(TTY_IO_ERROR, &tty->flags);
1043 tty_ldisc_flush(tty);
1048 if (portp->openwaitcnt) {
1049 if (portp->close_delay)
1050 msleep_interruptible(jiffies_to_msecs(portp->close_delay));
1051 wake_up_interruptible(&portp->open_wait);
1054 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1055 wake_up_interruptible(&portp->close_wait);
1058 /*****************************************************************************/
1061 * Write routine. Take data and stuff it in to the TX ring queue.
1062 * If transmit interrupts are not running then start them.
1065 static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
1067 struct stlport *portp;
1068 unsigned int len, stlen;
1069 unsigned char *chbuf;
1072 pr_debug("stl_write(tty=%p,buf=%p,count=%d)\n", tty, buf, count);
1074 portp = tty->driver_data;
1077 if (portp->tx.buf == NULL)
1081 * If copying direct from user space we must cater for page faults,
1082 * causing us to "sleep" here for a while. To handle this copy in all
1083 * the data we need now, into a local buffer. Then when we got it all
1084 * copy it into the TX buffer.
1086 chbuf = (unsigned char *) buf;
1088 head = portp->tx.head;
1089 tail = portp->tx.tail;
1091 len = STL_TXBUFSIZE - (head - tail) - 1;
1092 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
1094 len = tail - head - 1;
1098 len = MIN(len, count);
1101 stlen = MIN(len, stlen);
1102 memcpy(head, chbuf, stlen);
1107 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
1108 head = portp->tx.buf;
1109 stlen = tail - head;
1112 portp->tx.head = head;
1114 clear_bit(ASYI_TXLOW, &portp->istate);
1115 stl_startrxtx(portp, -1, 1);
1120 /*****************************************************************************/
1122 static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1124 struct stlport *portp;
1128 pr_debug("stl_putchar(tty=%p,ch=%x)\n", tty, ch);
1132 portp = tty->driver_data;
1135 if (portp->tx.buf == NULL)
1138 head = portp->tx.head;
1139 tail = portp->tx.tail;
1141 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
1146 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
1147 head = portp->tx.buf;
1149 portp->tx.head = head;
1152 /*****************************************************************************/
1155 * If there are any characters in the buffer then make sure that TX
1156 * interrupts are on and get'em out. Normally used after the putchar
1157 * routine has been called.
1160 static void stl_flushchars(struct tty_struct *tty)
1162 struct stlport *portp;
1164 pr_debug("stl_flushchars(tty=%p)\n", tty);
1168 portp = tty->driver_data;
1171 if (portp->tx.buf == NULL)
1174 stl_startrxtx(portp, -1, 1);
1177 /*****************************************************************************/
1179 static int stl_writeroom(struct tty_struct *tty)
1181 struct stlport *portp;
1184 pr_debug("stl_writeroom(tty=%p)\n", tty);
1188 portp = tty->driver_data;
1191 if (portp->tx.buf == NULL)
1194 head = portp->tx.head;
1195 tail = portp->tx.tail;
1196 return ((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
1199 /*****************************************************************************/
1202 * Return number of chars in the TX buffer. Normally we would just
1203 * calculate the number of chars in the buffer and return that, but if
1204 * the buffer is empty and TX interrupts are still on then we return
1205 * that the buffer still has 1 char in it. This way whoever called us
1206 * will not think that ALL chars have drained - since the UART still
1207 * must have some chars in it (we are busy after all).
1210 static int stl_charsinbuffer(struct tty_struct *tty)
1212 struct stlport *portp;
1216 pr_debug("stl_charsinbuffer(tty=%p)\n", tty);
1220 portp = tty->driver_data;
1223 if (portp->tx.buf == NULL)
1226 head = portp->tx.head;
1227 tail = portp->tx.tail;
1228 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1229 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1234 /*****************************************************************************/
1237 * Generate the serial struct info.
1240 static int stl_getserial(struct stlport *portp, struct serial_struct __user *sp)
1242 struct serial_struct sio;
1243 struct stlbrd *brdp;
1245 pr_debug("stl_getserial(portp=%p,sp=%p)\n", portp, sp);
1247 memset(&sio, 0, sizeof(struct serial_struct));
1248 sio.line = portp->portnr;
1249 sio.port = portp->ioaddr;
1250 sio.flags = portp->flags;
1251 sio.baud_base = portp->baud_base;
1252 sio.close_delay = portp->close_delay;
1253 sio.closing_wait = portp->closing_wait;
1254 sio.custom_divisor = portp->custom_divisor;
1256 if (portp->uartp == &stl_cd1400uart) {
1257 sio.type = PORT_CIRRUS;
1258 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1260 sio.type = PORT_UNKNOWN;
1261 sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1264 brdp = stl_brds[portp->brdnr];
1266 sio.irq = brdp->irq;
1268 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
1271 /*****************************************************************************/
1274 * Set port according to the serial struct info.
1275 * At this point we do not do any auto-configure stuff, so we will
1276 * just quietly ignore any requests to change irq, etc.
1279 static int stl_setserial(struct stlport *portp, struct serial_struct __user *sp)
1281 struct serial_struct sio;
1283 pr_debug("stl_setserial(portp=%p,sp=%p)\n", portp, sp);
1285 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1287 if (!capable(CAP_SYS_ADMIN)) {
1288 if ((sio.baud_base != portp->baud_base) ||
1289 (sio.close_delay != portp->close_delay) ||
1290 ((sio.flags & ~ASYNC_USR_MASK) !=
1291 (portp->flags & ~ASYNC_USR_MASK)))
1295 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1296 (sio.flags & ASYNC_USR_MASK);
1297 portp->baud_base = sio.baud_base;
1298 portp->close_delay = sio.close_delay;
1299 portp->closing_wait = sio.closing_wait;
1300 portp->custom_divisor = sio.custom_divisor;
1301 stl_setport(portp, portp->tty->termios);
1305 /*****************************************************************************/
1307 static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1309 struct stlport *portp;
1313 portp = tty->driver_data;
1316 if (tty->flags & (1 << TTY_IO_ERROR))
1319 return stl_getsignals(portp);
1322 static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1323 unsigned int set, unsigned int clear)
1325 struct stlport *portp;
1326 int rts = -1, dtr = -1;
1330 portp = tty->driver_data;
1333 if (tty->flags & (1 << TTY_IO_ERROR))
1336 if (set & TIOCM_RTS)
1338 if (set & TIOCM_DTR)
1340 if (clear & TIOCM_RTS)
1342 if (clear & TIOCM_DTR)
1345 stl_setsignals(portp, dtr, rts);
1349 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1351 struct stlport *portp;
1354 void __user *argp = (void __user *)arg;
1356 pr_debug("stl_ioctl(tty=%p,file=%p,cmd=%x,arg=%lx)\n", tty, file, cmd,
1361 portp = tty->driver_data;
1365 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1366 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1367 if (tty->flags & (1 << TTY_IO_ERROR))
1375 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1376 (unsigned __user *) argp);
1379 if (get_user(ival, (unsigned int __user *) arg))
1381 tty->termios->c_cflag =
1382 (tty->termios->c_cflag & ~CLOCAL) |
1383 (ival ? CLOCAL : 0);
1386 rc = stl_getserial(portp, argp);
1389 rc = stl_setserial(portp, argp);
1391 case COM_GETPORTSTATS:
1392 rc = stl_getportstats(portp, argp);
1394 case COM_CLRPORTSTATS:
1395 rc = stl_clrportstats(portp, argp);
1401 case TIOCSERGSTRUCT:
1402 case TIOCSERGETMULTI:
1403 case TIOCSERSETMULTI:
1412 /*****************************************************************************/
1414 static void stl_settermios(struct tty_struct *tty, struct termios *old)
1416 struct stlport *portp;
1417 struct termios *tiosp;
1419 pr_debug("stl_settermios(tty=%p,old=%p)\n", tty, old);
1423 portp = tty->driver_data;
1427 tiosp = tty->termios;
1428 if ((tiosp->c_cflag == old->c_cflag) &&
1429 (tiosp->c_iflag == old->c_iflag))
1432 stl_setport(portp, tiosp);
1433 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1435 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1436 tty->hw_stopped = 0;
1439 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1440 wake_up_interruptible(&portp->open_wait);
1443 /*****************************************************************************/
1446 * Attempt to flow control who ever is sending us data. Based on termios
1447 * settings use software or/and hardware flow control.
1450 static void stl_throttle(struct tty_struct *tty)
1452 struct stlport *portp;
1454 pr_debug("stl_throttle(tty=%p)\n", tty);
1458 portp = tty->driver_data;
1461 stl_flowctrl(portp, 0);
1464 /*****************************************************************************/
1467 * Unflow control the device sending us data...
1470 static void stl_unthrottle(struct tty_struct *tty)
1472 struct stlport *portp;
1474 pr_debug("stl_unthrottle(tty=%p)\n", tty);
1478 portp = tty->driver_data;
1481 stl_flowctrl(portp, 1);
1484 /*****************************************************************************/
1487 * Stop the transmitter. Basically to do this we will just turn TX
1491 static void stl_stop(struct tty_struct *tty)
1493 struct stlport *portp;
1495 pr_debug("stl_stop(tty=%p)\n", tty);
1499 portp = tty->driver_data;
1502 stl_startrxtx(portp, -1, 0);
1505 /*****************************************************************************/
1508 * Start the transmitter again. Just turn TX interrupts back on.
1511 static void stl_start(struct tty_struct *tty)
1513 struct stlport *portp;
1515 pr_debug("stl_start(tty=%p)\n", tty);
1519 portp = tty->driver_data;
1522 stl_startrxtx(portp, -1, 1);
1525 /*****************************************************************************/
1528 * Hangup this port. This is pretty much like closing the port, only
1529 * a little more brutal. No waiting for data to drain. Shutdown the
1530 * port and maybe drop signals.
1533 static void stl_hangup(struct tty_struct *tty)
1535 struct stlport *portp;
1537 pr_debug("stl_hangup(tty=%p)\n", tty);
1541 portp = tty->driver_data;
1545 portp->flags &= ~ASYNC_INITIALIZED;
1546 stl_disableintrs(portp);
1547 if (tty->termios->c_cflag & HUPCL)
1548 stl_setsignals(portp, 0, 0);
1549 stl_enablerxtx(portp, 0, 0);
1550 stl_flushbuffer(tty);
1552 set_bit(TTY_IO_ERROR, &tty->flags);
1553 if (portp->tx.buf != NULL) {
1554 kfree(portp->tx.buf);
1555 portp->tx.buf = NULL;
1556 portp->tx.head = NULL;
1557 portp->tx.tail = NULL;
1560 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1561 portp->refcount = 0;
1562 wake_up_interruptible(&portp->open_wait);
1565 /*****************************************************************************/
1567 static void stl_flushbuffer(struct tty_struct *tty)
1569 struct stlport *portp;
1571 pr_debug("stl_flushbuffer(tty=%p)\n", tty);
1575 portp = tty->driver_data;
1583 /*****************************************************************************/
1585 static void stl_breakctl(struct tty_struct *tty, int state)
1587 struct stlport *portp;
1589 pr_debug("stl_breakctl(tty=%p,state=%d)\n", tty, state);
1593 portp = tty->driver_data;
1597 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1600 /*****************************************************************************/
1602 static void stl_waituntilsent(struct tty_struct *tty, int timeout)
1604 struct stlport *portp;
1607 pr_debug("stl_waituntilsent(tty=%p,timeout=%d)\n", tty, timeout);
1611 portp = tty->driver_data;
1617 tend = jiffies + timeout;
1619 while (stl_datastate(portp)) {
1620 if (signal_pending(current))
1622 msleep_interruptible(20);
1623 if (time_after_eq(jiffies, tend))
1628 /*****************************************************************************/
1630 static void stl_sendxchar(struct tty_struct *tty, char ch)
1632 struct stlport *portp;
1634 pr_debug("stl_sendxchar(tty=%p,ch=%x)\n", tty, ch);
1638 portp = tty->driver_data;
1642 if (ch == STOP_CHAR(tty))
1643 stl_sendflow(portp, 0);
1644 else if (ch == START_CHAR(tty))
1645 stl_sendflow(portp, 1);
1647 stl_putchar(tty, ch);
1650 /*****************************************************************************/
1655 * Format info for a specified port. The line is deliberately limited
1656 * to 80 characters. (If it is too long it will be truncated, if too
1657 * short then padded with spaces).
1660 static int stl_portinfo(struct stlport *portp, int portnr, char *pos)
1666 sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
1667 portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
1668 (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
1670 if (portp->stats.rxframing)
1671 sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
1672 if (portp->stats.rxparity)
1673 sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
1674 if (portp->stats.rxbreaks)
1675 sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
1676 if (portp->stats.rxoverrun)
1677 sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
1679 sigs = stl_getsignals(portp);
1680 cnt = sprintf(sp, "%s%s%s%s%s ",
1681 (sigs & TIOCM_RTS) ? "|RTS" : "",
1682 (sigs & TIOCM_CTS) ? "|CTS" : "",
1683 (sigs & TIOCM_DTR) ? "|DTR" : "",
1684 (sigs & TIOCM_CD) ? "|DCD" : "",
1685 (sigs & TIOCM_DSR) ? "|DSR" : "");
1689 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
1692 pos[(MAXLINE - 2)] = '+';
1693 pos[(MAXLINE - 1)] = '\n';
1698 /*****************************************************************************/
1701 * Port info, read from the /proc file system.
1704 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
1706 struct stlbrd *brdp;
1707 struct stlpanel *panelp;
1708 struct stlport *portp;
1709 int brdnr, panelnr, portnr, totalport;
1713 pr_debug("stl_readproc(page=%p,start=%p,off=%lx,count=%d,eof=%p,"
1714 "data=%p\n", page, start, off, count, eof, data);
1721 pos += sprintf(pos, "%s: version %s", stl_drvtitle,
1723 while (pos < (page + MAXLINE - 1))
1730 * We scan through for each board, panel and port. The offset is
1731 * calculated on the fly, and irrelevant ports are skipped.
1733 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1734 brdp = stl_brds[brdnr];
1737 if (brdp->state == 0)
1740 maxoff = curoff + (brdp->nrports * MAXLINE);
1741 if (off >= maxoff) {
1746 totalport = brdnr * STL_MAXPORTS;
1747 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1748 panelp = brdp->panels[panelnr];
1752 maxoff = curoff + (panelp->nrports * MAXLINE);
1753 if (off >= maxoff) {
1755 totalport += panelp->nrports;
1759 for (portnr = 0; (portnr < panelp->nrports); portnr++,
1761 portp = panelp->ports[portnr];
1764 if (off >= (curoff += MAXLINE))
1766 if ((pos - page + MAXLINE) > count)
1768 pos += stl_portinfo(portp, totalport, pos);
1777 return (pos - page);
1780 /*****************************************************************************/
1783 * All board interrupts are vectored through here first. This code then
1784 * calls off to the approrpriate board interrupt handlers.
1787 static irqreturn_t stl_intr(int irq, void *dev_id)
1789 struct stlbrd *brdp = dev_id;
1791 pr_debug("stl_intr(brdp=%p,irq=%d)\n", brdp, irq);
1793 return IRQ_RETVAL((* brdp->isr)(brdp));
1796 /*****************************************************************************/
1799 * Interrupt service routine for EasyIO board types.
1802 static int stl_eiointr(struct stlbrd *brdp)
1804 struct stlpanel *panelp;
1805 unsigned int iobase;
1808 spin_lock(&brd_lock);
1809 panelp = brdp->panels[0];
1810 iobase = panelp->iobase;
1811 while (inb(brdp->iostatus) & EIO_INTRPEND) {
1813 (* panelp->isr)(panelp, iobase);
1815 spin_unlock(&brd_lock);
1819 /*****************************************************************************/
1822 * Interrupt service routine for ECH-AT board types.
1825 static int stl_echatintr(struct stlbrd *brdp)
1827 struct stlpanel *panelp;
1828 unsigned int ioaddr;
1832 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
1834 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1836 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1837 ioaddr = brdp->bnkstataddr[bnknr];
1838 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1839 panelp = brdp->bnk2panel[bnknr];
1840 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1845 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
1850 /*****************************************************************************/
1853 * Interrupt service routine for ECH-MCA board types.
1856 static int stl_echmcaintr(struct stlbrd *brdp)
1858 struct stlpanel *panelp;
1859 unsigned int ioaddr;
1863 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1865 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1866 ioaddr = brdp->bnkstataddr[bnknr];
1867 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1868 panelp = brdp->bnk2panel[bnknr];
1869 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1876 /*****************************************************************************/
1879 * Interrupt service routine for ECH-PCI board types.
1882 static int stl_echpciintr(struct stlbrd *brdp)
1884 struct stlpanel *panelp;
1885 unsigned int ioaddr;
1891 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1892 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
1893 ioaddr = brdp->bnkstataddr[bnknr];
1894 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1895 panelp = brdp->bnk2panel[bnknr];
1896 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1907 /*****************************************************************************/
1910 * Interrupt service routine for ECH-8/64-PCI board types.
1913 static int stl_echpci64intr(struct stlbrd *brdp)
1915 struct stlpanel *panelp;
1916 unsigned int ioaddr;
1920 while (inb(brdp->ioctrl) & 0x1) {
1922 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1923 ioaddr = brdp->bnkstataddr[bnknr];
1924 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1925 panelp = brdp->bnk2panel[bnknr];
1926 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1934 /*****************************************************************************/
1937 * Service an off-level request for some channel.
1939 static void stl_offintr(struct work_struct *work)
1941 struct stlport *portp = container_of(work, struct stlport, tqueue);
1942 struct tty_struct *tty;
1943 unsigned int oldsigs;
1945 pr_debug("stl_offintr(portp=%p)\n", portp);
1955 if (test_bit(ASYI_TXLOW, &portp->istate)) {
1958 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
1959 clear_bit(ASYI_DCDCHANGE, &portp->istate);
1960 oldsigs = portp->sigs;
1961 portp->sigs = stl_getsignals(portp);
1962 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
1963 wake_up_interruptible(&portp->open_wait);
1964 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
1965 if (portp->flags & ASYNC_CHECK_CD)
1966 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
1972 /*****************************************************************************/
1975 * Initialize all the ports on a panel.
1978 static int __init stl_initports(struct stlbrd *brdp, struct stlpanel *panelp)
1980 struct stlport *portp;
1983 pr_debug("stl_initports(brdp=%p,panelp=%p)\n", brdp, panelp);
1985 chipmask = stl_panelinit(brdp, panelp);
1988 * All UART's are initialized (if found!). Now go through and setup
1989 * each ports data structures.
1991 for (i = 0; (i < panelp->nrports); i++) {
1992 portp = kzalloc(sizeof(struct stlport), GFP_KERNEL);
1994 printk("STALLION: failed to allocate memory "
1995 "(size=%Zd)\n", sizeof(struct stlport));
1999 portp->magic = STL_PORTMAGIC;
2001 portp->brdnr = panelp->brdnr;
2002 portp->panelnr = panelp->panelnr;
2003 portp->uartp = panelp->uartp;
2004 portp->clk = brdp->clk;
2005 portp->baud_base = STL_BAUDBASE;
2006 portp->close_delay = STL_CLOSEDELAY;
2007 portp->closing_wait = 30 * HZ;
2008 INIT_WORK(&portp->tqueue, stl_offintr);
2009 init_waitqueue_head(&portp->open_wait);
2010 init_waitqueue_head(&portp->close_wait);
2011 portp->stats.brd = portp->brdnr;
2012 portp->stats.panel = portp->panelnr;
2013 portp->stats.port = portp->portnr;
2014 panelp->ports[i] = portp;
2015 stl_portinit(brdp, panelp, portp);
2021 /*****************************************************************************/
2024 * Try to find and initialize an EasyIO board.
2027 static inline int stl_initeio(struct stlbrd *brdp)
2029 struct stlpanel *panelp;
2030 unsigned int status;
2034 pr_debug("stl_initeio(brdp=%p)\n", brdp);
2036 brdp->ioctrl = brdp->ioaddr1 + 1;
2037 brdp->iostatus = brdp->ioaddr1 + 2;
2039 status = inb(brdp->iostatus);
2040 if ((status & EIO_IDBITMASK) == EIO_MK3)
2044 * Handle board specific stuff now. The real difference is PCI
2047 if (brdp->brdtype == BRD_EASYIOPCI) {
2048 brdp->iosize1 = 0x80;
2049 brdp->iosize2 = 0x80;
2050 name = "serial(EIO-PCI)";
2051 outb(0x41, (brdp->ioaddr2 + 0x4c));
2054 name = "serial(EIO)";
2055 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2056 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2057 printk("STALLION: invalid irq=%d for brd=%d\n",
2058 brdp->irq, brdp->brdnr);
2061 outb((stl_vecmap[brdp->irq] | EIO_0WS |
2062 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
2066 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2067 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2068 "%x conflicts with another device\n", brdp->brdnr,
2073 if (brdp->iosize2 > 0)
2074 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2075 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2076 "address %x conflicts with another device\n",
2077 brdp->brdnr, brdp->ioaddr2);
2078 printk(KERN_WARNING "STALLION: Warning, also "
2079 "releasing board %d I/O address %x \n",
2080 brdp->brdnr, brdp->ioaddr1);
2081 release_region(brdp->ioaddr1, brdp->iosize1);
2086 * Everything looks OK, so let's go ahead and probe for the hardware.
2088 brdp->clk = CD1400_CLK;
2089 brdp->isr = stl_eiointr;
2091 switch (status & EIO_IDBITMASK) {
2093 brdp->clk = CD1400_CLK8M;
2103 switch (status & EIO_BRDMASK) {
2122 * We have verified that the board is actually present, so now we
2123 * can complete the setup.
2126 panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
2128 printk(KERN_WARNING "STALLION: failed to allocate memory "
2129 "(size=%Zd)\n", sizeof(struct stlpanel));
2133 panelp->magic = STL_PANELMAGIC;
2134 panelp->brdnr = brdp->brdnr;
2135 panelp->panelnr = 0;
2136 panelp->nrports = brdp->nrports;
2137 panelp->iobase = brdp->ioaddr1;
2138 panelp->hwid = status;
2139 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2140 panelp->uartp = &stl_sc26198uart;
2141 panelp->isr = stl_sc26198intr;
2143 panelp->uartp = &stl_cd1400uart;
2144 panelp->isr = stl_cd1400eiointr;
2147 brdp->panels[0] = panelp;
2149 brdp->state |= BRD_FOUND;
2150 brdp->hwid = status;
2151 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
2152 printk("STALLION: failed to register interrupt "
2153 "routine for %s irq=%d\n", name, brdp->irq);
2161 /*****************************************************************************/
2164 * Try to find an ECH board and initialize it. This code is capable of
2165 * dealing with all types of ECH board.
2168 static inline int stl_initech(struct stlbrd *brdp)
2170 struct stlpanel *panelp;
2171 unsigned int status, nxtid, ioaddr, conflict;
2172 int panelnr, banknr, i;
2175 pr_debug("stl_initech(brdp=%p)\n", brdp);
2181 * Set up the initial board register contents for boards. This varies a
2182 * bit between the different board types. So we need to handle each
2183 * separately. Also do a check that the supplied IRQ is good.
2185 switch (brdp->brdtype) {
2188 brdp->isr = stl_echatintr;
2189 brdp->ioctrl = brdp->ioaddr1 + 1;
2190 brdp->iostatus = brdp->ioaddr1 + 1;
2191 status = inb(brdp->iostatus);
2192 if ((status & ECH_IDBITMASK) != ECH_ID)
2194 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2195 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2196 printk("STALLION: invalid irq=%d for brd=%d\n",
2197 brdp->irq, brdp->brdnr);
2200 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2201 status |= (stl_vecmap[brdp->irq] << 1);
2202 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2203 brdp->ioctrlval = ECH_INTENABLE |
2204 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2205 for (i = 0; (i < 10); i++)
2206 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2209 name = "serial(EC8/32)";
2210 outb(status, brdp->ioaddr1);
2214 brdp->isr = stl_echmcaintr;
2215 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2216 brdp->iostatus = brdp->ioctrl;
2217 status = inb(brdp->iostatus);
2218 if ((status & ECH_IDBITMASK) != ECH_ID)
2220 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2221 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2222 printk("STALLION: invalid irq=%d for brd=%d\n",
2223 brdp->irq, brdp->brdnr);
2226 outb(ECHMC_BRDRESET, brdp->ioctrl);
2227 outb(ECHMC_INTENABLE, brdp->ioctrl);
2229 name = "serial(EC8/32-MC)";
2233 brdp->isr = stl_echpciintr;
2234 brdp->ioctrl = brdp->ioaddr1 + 2;
2237 name = "serial(EC8/32-PCI)";
2241 brdp->isr = stl_echpci64intr;
2242 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2243 outb(0x43, (brdp->ioaddr1 + 0x4c));
2244 brdp->iosize1 = 0x80;
2245 brdp->iosize2 = 0x80;
2246 name = "serial(EC8/64-PCI)";
2250 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
2256 * Check boards for possible IO address conflicts and return fail status
2257 * if an IO conflict found.
2259 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2260 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2261 "%x conflicts with another device\n", brdp->brdnr,
2266 if (brdp->iosize2 > 0)
2267 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2268 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2269 "address %x conflicts with another device\n",
2270 brdp->brdnr, brdp->ioaddr2);
2271 printk(KERN_WARNING "STALLION: Warning, also "
2272 "releasing board %d I/O address %x \n",
2273 brdp->brdnr, brdp->ioaddr1);
2274 release_region(brdp->ioaddr1, brdp->iosize1);
2279 * Scan through the secondary io address space looking for panels.
2280 * As we find'em allocate and initialize panel structures for each.
2282 brdp->clk = CD1400_CLK;
2283 brdp->hwid = status;
2285 ioaddr = brdp->ioaddr2;
2290 for (i = 0; (i < STL_MAXPANELS); i++) {
2291 if (brdp->brdtype == BRD_ECHPCI) {
2292 outb(nxtid, brdp->ioctrl);
2293 ioaddr = brdp->ioaddr2;
2295 status = inb(ioaddr + ECH_PNLSTATUS);
2296 if ((status & ECH_PNLIDMASK) != nxtid)
2298 panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
2300 printk("STALLION: failed to allocate memory "
2301 "(size=%Zd)\n", sizeof(struct stlpanel));
2304 panelp->magic = STL_PANELMAGIC;
2305 panelp->brdnr = brdp->brdnr;
2306 panelp->panelnr = panelnr;
2307 panelp->iobase = ioaddr;
2308 panelp->pagenr = nxtid;
2309 panelp->hwid = status;
2310 brdp->bnk2panel[banknr] = panelp;
2311 brdp->bnkpageaddr[banknr] = nxtid;
2312 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2314 if (status & ECH_PNLXPID) {
2315 panelp->uartp = &stl_sc26198uart;
2316 panelp->isr = stl_sc26198intr;
2317 if (status & ECH_PNL16PORT) {
2318 panelp->nrports = 16;
2319 brdp->bnk2panel[banknr] = panelp;
2320 brdp->bnkpageaddr[banknr] = nxtid;
2321 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2324 panelp->nrports = 8;
2327 panelp->uartp = &stl_cd1400uart;
2328 panelp->isr = stl_cd1400echintr;
2329 if (status & ECH_PNL16PORT) {
2330 panelp->nrports = 16;
2331 panelp->ackmask = 0x80;
2332 if (brdp->brdtype != BRD_ECHPCI)
2333 ioaddr += EREG_BANKSIZE;
2334 brdp->bnk2panel[banknr] = panelp;
2335 brdp->bnkpageaddr[banknr] = ++nxtid;
2336 brdp->bnkstataddr[banknr++] = ioaddr +
2339 panelp->nrports = 8;
2340 panelp->ackmask = 0xc0;
2345 ioaddr += EREG_BANKSIZE;
2346 brdp->nrports += panelp->nrports;
2347 brdp->panels[panelnr++] = panelp;
2348 if ((brdp->brdtype != BRD_ECHPCI) &&
2349 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
2353 brdp->nrpanels = panelnr;
2354 brdp->nrbnks = banknr;
2355 if (brdp->brdtype == BRD_ECH)
2356 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2358 brdp->state |= BRD_FOUND;
2359 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
2360 printk("STALLION: failed to register interrupt "
2361 "routine for %s irq=%d\n", name, brdp->irq);
2370 /*****************************************************************************/
2373 * Initialize and configure the specified board.
2374 * Scan through all the boards in the configuration and see what we
2375 * can find. Handle EIO and the ECH boards a little differently here
2376 * since the initial search and setup is very different.
2379 static int __init stl_brdinit(struct stlbrd *brdp)
2383 pr_debug("stl_brdinit(brdp=%p)\n", brdp);
2385 switch (brdp->brdtype) {
2397 printk("STALLION: board=%d is unknown board type=%d\n",
2398 brdp->brdnr, brdp->brdtype);
2402 stl_brds[brdp->brdnr] = brdp;
2403 if ((brdp->state & BRD_FOUND) == 0) {
2404 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2405 stl_brdnames[brdp->brdtype], brdp->brdnr,
2406 brdp->ioaddr1, brdp->irq);
2410 for (i = 0; (i < STL_MAXPANELS); i++)
2411 if (brdp->panels[i] != NULL)
2412 stl_initports(brdp, brdp->panels[i]);
2414 printk("STALLION: %s found, board=%d io=%x irq=%d "
2415 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2416 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2421 /*****************************************************************************/
2424 * Find the next available board number that is free.
2427 static inline int stl_getbrdnr(void)
2431 for (i = 0; (i < STL_MAXBRDS); i++) {
2432 if (stl_brds[i] == NULL) {
2433 if (i >= stl_nrbrds)
2441 /*****************************************************************************/
2446 * We have a Stallion board. Allocate a board structure and
2447 * initialize it. Read its IO and IRQ resources from PCI
2448 * configuration space.
2451 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
2453 struct stlbrd *brdp;
2455 pr_debug("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
2456 devp->bus->number, devp->devfn);
2458 if (pci_enable_device(devp))
2460 if ((brdp = stl_allocbrd()) == NULL)
2462 if ((brdp->brdnr = stl_getbrdnr()) < 0) {
2463 printk("STALLION: too many boards found, "
2464 "maximum supported %d\n", STL_MAXBRDS);
2467 brdp->brdtype = brdtype;
2470 * Different Stallion boards use the BAR registers in different ways,
2471 * so set up io addresses based on board type.
2473 pr_debug("%s(%d): BAR[]=%Lx,%Lx,%Lx,%Lx IRQ=%x\n", __FILE__, __LINE__,
2474 pci_resource_start(devp, 0), pci_resource_start(devp, 1),
2475 pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
2478 * We have all resources from the board, so let's setup the actual
2479 * board structure now.
2483 brdp->ioaddr2 = pci_resource_start(devp, 0);
2484 brdp->ioaddr1 = pci_resource_start(devp, 1);
2487 brdp->ioaddr2 = pci_resource_start(devp, 2);
2488 brdp->ioaddr1 = pci_resource_start(devp, 1);
2491 brdp->ioaddr1 = pci_resource_start(devp, 2);
2492 brdp->ioaddr2 = pci_resource_start(devp, 1);
2495 printk("STALLION: unknown PCI board type=%d\n", brdtype);
2499 brdp->irq = devp->irq;
2505 /*****************************************************************************/
2508 * Find all Stallion PCI boards that might be installed. Initialize each
2509 * one as it is found.
2513 static inline int stl_findpcibrds(void)
2515 struct pci_dev *dev = NULL;
2518 pr_debug("stl_findpcibrds()\n");
2520 for (i = 0; (i < stl_nrpcibrds); i++)
2521 while ((dev = pci_find_device(stl_pcibrds[i].vendid,
2522 stl_pcibrds[i].devid, dev))) {
2525 * Found a device on the PCI bus that has our vendor and
2526 * device ID. Need to check now that it is really us.
2528 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2531 rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
2541 /*****************************************************************************/
2544 * Scan through all the boards in the configuration and see what we
2545 * can find. Handle EIO and the ECH boards a little differently here
2546 * since the initial search and setup is too different.
2549 static inline int stl_initbrds(void)
2551 struct stlbrd *brdp;
2552 struct stlconf *confp;
2555 pr_debug("stl_initbrds()\n");
2557 if (stl_nrbrds > STL_MAXBRDS) {
2558 printk("STALLION: too many boards in configuration table, "
2559 "truncating to %d\n", STL_MAXBRDS);
2560 stl_nrbrds = STL_MAXBRDS;
2564 * Firstly scan the list of static boards configured. Allocate
2565 * resources and initialize the boards as found.
2567 for (i = 0; (i < stl_nrbrds); i++) {
2568 confp = &stl_brdconf[i];
2569 stl_parsebrd(confp, stl_brdsp[i]);
2570 if ((brdp = stl_allocbrd()) == NULL)
2573 brdp->brdtype = confp->brdtype;
2574 brdp->ioaddr1 = confp->ioaddr1;
2575 brdp->ioaddr2 = confp->ioaddr2;
2576 brdp->irq = confp->irq;
2577 brdp->irqtype = confp->irqtype;
2582 * Find any dynamically supported boards. That is via module load
2583 * line options or auto-detected on the PCI bus.
2593 /*****************************************************************************/
2596 * Return the board stats structure to user app.
2599 static int stl_getbrdstats(combrd_t __user *bp)
2601 struct stlbrd *brdp;
2602 struct stlpanel *panelp;
2605 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2607 if (stl_brdstats.brd >= STL_MAXBRDS)
2609 brdp = stl_brds[stl_brdstats.brd];
2613 memset(&stl_brdstats, 0, sizeof(combrd_t));
2614 stl_brdstats.brd = brdp->brdnr;
2615 stl_brdstats.type = brdp->brdtype;
2616 stl_brdstats.hwid = brdp->hwid;
2617 stl_brdstats.state = brdp->state;
2618 stl_brdstats.ioaddr = brdp->ioaddr1;
2619 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2620 stl_brdstats.irq = brdp->irq;
2621 stl_brdstats.nrpanels = brdp->nrpanels;
2622 stl_brdstats.nrports = brdp->nrports;
2623 for (i = 0; (i < brdp->nrpanels); i++) {
2624 panelp = brdp->panels[i];
2625 stl_brdstats.panels[i].panel = i;
2626 stl_brdstats.panels[i].hwid = panelp->hwid;
2627 stl_brdstats.panels[i].nrports = panelp->nrports;
2630 return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
2633 /*****************************************************************************/
2636 * Resolve the referenced port number into a port struct pointer.
2639 static struct stlport *stl_getport(int brdnr, int panelnr, int portnr)
2641 struct stlbrd *brdp;
2642 struct stlpanel *panelp;
2644 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2646 brdp = stl_brds[brdnr];
2649 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2651 panelp = brdp->panels[panelnr];
2654 if ((portnr < 0) || (portnr >= panelp->nrports))
2656 return(panelp->ports[portnr]);
2659 /*****************************************************************************/
2662 * Return the port stats structure to user app. A NULL port struct
2663 * pointer passed in means that we need to find out from the app
2664 * what port to get stats for (used through board control device).
2667 static int stl_getportstats(struct stlport *portp, comstats_t __user *cp)
2669 unsigned char *head, *tail;
2670 unsigned long flags;
2673 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2675 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2681 portp->stats.state = portp->istate;
2682 portp->stats.flags = portp->flags;
2683 portp->stats.hwid = portp->hwid;
2685 portp->stats.ttystate = 0;
2686 portp->stats.cflags = 0;
2687 portp->stats.iflags = 0;
2688 portp->stats.oflags = 0;
2689 portp->stats.lflags = 0;
2690 portp->stats.rxbuffered = 0;
2692 spin_lock_irqsave(&stallion_lock, flags);
2693 if (portp->tty != NULL) {
2694 if (portp->tty->driver_data == portp) {
2695 portp->stats.ttystate = portp->tty->flags;
2696 /* No longer available as a statistic */
2697 portp->stats.rxbuffered = 1; /*portp->tty->flip.count; */
2698 if (portp->tty->termios != NULL) {
2699 portp->stats.cflags = portp->tty->termios->c_cflag;
2700 portp->stats.iflags = portp->tty->termios->c_iflag;
2701 portp->stats.oflags = portp->tty->termios->c_oflag;
2702 portp->stats.lflags = portp->tty->termios->c_lflag;
2706 spin_unlock_irqrestore(&stallion_lock, flags);
2708 head = portp->tx.head;
2709 tail = portp->tx.tail;
2710 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2711 (STL_TXBUFSIZE - (tail - head)));
2713 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2715 return copy_to_user(cp, &portp->stats,
2716 sizeof(comstats_t)) ? -EFAULT : 0;
2719 /*****************************************************************************/
2722 * Clear the port stats structure. We also return it zeroed out...
2725 static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp)
2728 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2730 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2736 memset(&portp->stats, 0, sizeof(comstats_t));
2737 portp->stats.brd = portp->brdnr;
2738 portp->stats.panel = portp->panelnr;
2739 portp->stats.port = portp->portnr;
2740 return copy_to_user(cp, &portp->stats,
2741 sizeof(comstats_t)) ? -EFAULT : 0;
2744 /*****************************************************************************/
2747 * Return the entire driver ports structure to a user app.
2750 static int stl_getportstruct(struct stlport __user *arg)
2752 struct stlport *portp;
2754 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
2756 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
2757 stl_dummyport.portnr);
2760 return copy_to_user(arg, portp, sizeof(struct stlport)) ? -EFAULT : 0;
2763 /*****************************************************************************/
2766 * Return the entire driver board structure to a user app.
2769 static int stl_getbrdstruct(struct stlbrd __user *arg)
2771 struct stlbrd *brdp;
2773 if (copy_from_user(&stl_dummybrd, arg, sizeof(struct stlbrd)))
2775 if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
2777 brdp = stl_brds[stl_dummybrd.brdnr];
2780 return copy_to_user(arg, brdp, sizeof(struct stlbrd)) ? -EFAULT : 0;
2783 /*****************************************************************************/
2786 * The "staliomem" device is also required to do some special operations
2787 * on the board and/or ports. In this driver it is mostly used for stats
2791 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
2794 void __user *argp = (void __user *)arg;
2796 pr_debug("stl_memioctl(ip=%p,fp=%p,cmd=%x,arg=%lx)\n", ip, fp, cmd,arg);
2799 if (brdnr >= STL_MAXBRDS)
2804 case COM_GETPORTSTATS:
2805 rc = stl_getportstats(NULL, argp);
2807 case COM_CLRPORTSTATS:
2808 rc = stl_clrportstats(NULL, argp);
2810 case COM_GETBRDSTATS:
2811 rc = stl_getbrdstats(argp);
2814 rc = stl_getportstruct(argp);
2817 rc = stl_getbrdstruct(argp);
2827 static const struct tty_operations stl_ops = {
2831 .put_char = stl_putchar,
2832 .flush_chars = stl_flushchars,
2833 .write_room = stl_writeroom,
2834 .chars_in_buffer = stl_charsinbuffer,
2836 .set_termios = stl_settermios,
2837 .throttle = stl_throttle,
2838 .unthrottle = stl_unthrottle,
2841 .hangup = stl_hangup,
2842 .flush_buffer = stl_flushbuffer,
2843 .break_ctl = stl_breakctl,
2844 .wait_until_sent = stl_waituntilsent,
2845 .send_xchar = stl_sendxchar,
2846 .read_proc = stl_readproc,
2847 .tiocmget = stl_tiocmget,
2848 .tiocmset = stl_tiocmset,
2851 /*****************************************************************************/
2852 /* CD1400 HARDWARE FUNCTIONS */
2853 /*****************************************************************************/
2856 * These functions get/set/update the registers of the cd1400 UARTs.
2857 * Access to the cd1400 registers is via an address/data io port pair.
2858 * (Maybe should make this inline...)
2861 static int stl_cd1400getreg(struct stlport *portp, int regnr)
2863 outb((regnr + portp->uartaddr), portp->ioaddr);
2864 return inb(portp->ioaddr + EREG_DATA);
2867 static void stl_cd1400setreg(struct stlport *portp, int regnr, int value)
2869 outb((regnr + portp->uartaddr), portp->ioaddr);
2870 outb(value, portp->ioaddr + EREG_DATA);
2873 static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value)
2875 outb((regnr + portp->uartaddr), portp->ioaddr);
2876 if (inb(portp->ioaddr + EREG_DATA) != value) {
2877 outb(value, portp->ioaddr + EREG_DATA);
2883 /*****************************************************************************/
2886 * Inbitialize the UARTs in a panel. We don't care what sort of board
2887 * these ports are on - since the port io registers are almost
2888 * identical when dealing with ports.
2891 static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
2895 int nrchips, uartaddr, ioaddr;
2896 unsigned long flags;
2898 pr_debug("stl_panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
2900 spin_lock_irqsave(&brd_lock, flags);
2901 BRDENABLE(panelp->brdnr, panelp->pagenr);
2904 * Check that each chip is present and started up OK.
2907 nrchips = panelp->nrports / CD1400_PORTS;
2908 for (i = 0; (i < nrchips); i++) {
2909 if (brdp->brdtype == BRD_ECHPCI) {
2910 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
2911 ioaddr = panelp->iobase;
2913 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
2915 uartaddr = (i & 0x01) ? 0x080 : 0;
2916 outb((GFRCR + uartaddr), ioaddr);
2917 outb(0, (ioaddr + EREG_DATA));
2918 outb((CCR + uartaddr), ioaddr);
2919 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
2920 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
2921 outb((GFRCR + uartaddr), ioaddr);
2922 for (j = 0; (j < CCR_MAXWAIT); j++) {
2923 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
2926 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
2927 printk("STALLION: cd1400 not responding, "
2928 "brd=%d panel=%d chip=%d\n",
2929 panelp->brdnr, panelp->panelnr, i);
2932 chipmask |= (0x1 << i);
2933 outb((PPR + uartaddr), ioaddr);
2934 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
2937 BRDDISABLE(panelp->brdnr);
2938 spin_unlock_irqrestore(&brd_lock, flags);
2942 /*****************************************************************************/
2945 * Initialize hardware specific port registers.
2948 static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
2950 unsigned long flags;
2951 pr_debug("stl_cd1400portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
2954 if ((brdp == NULL) || (panelp == NULL) ||
2958 spin_lock_irqsave(&brd_lock, flags);
2959 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
2960 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
2961 portp->uartaddr = (portp->portnr & 0x04) << 5;
2962 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
2964 BRDENABLE(portp->brdnr, portp->pagenr);
2965 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2966 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
2967 portp->hwid = stl_cd1400getreg(portp, GFRCR);
2968 BRDDISABLE(portp->brdnr);
2969 spin_unlock_irqrestore(&brd_lock, flags);
2972 /*****************************************************************************/
2975 * Wait for the command register to be ready. We will poll this,
2976 * since it won't usually take too long to be ready.
2979 static void stl_cd1400ccrwait(struct stlport *portp)
2983 for (i = 0; (i < CCR_MAXWAIT); i++) {
2984 if (stl_cd1400getreg(portp, CCR) == 0) {
2989 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
2990 portp->portnr, portp->panelnr, portp->brdnr);
2993 /*****************************************************************************/
2996 * Set up the cd1400 registers for a port based on the termios port
3000 static void stl_cd1400setport(struct stlport *portp, struct termios *tiosp)
3002 struct stlbrd *brdp;
3003 unsigned long flags;
3004 unsigned int clkdiv, baudrate;
3005 unsigned char cor1, cor2, cor3;
3006 unsigned char cor4, cor5, ccr;
3007 unsigned char srer, sreron, sreroff;
3008 unsigned char mcor1, mcor2, rtpr;
3009 unsigned char clk, div;
3025 brdp = stl_brds[portp->brdnr];
3030 * Set up the RX char ignore mask with those RX error types we
3031 * can ignore. We can get the cd1400 to help us out a little here,
3032 * it will ignore parity errors and breaks for us.
3034 portp->rxignoremsk = 0;
3035 if (tiosp->c_iflag & IGNPAR) {
3036 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
3037 cor1 |= COR1_PARIGNORE;
3039 if (tiosp->c_iflag & IGNBRK) {
3040 portp->rxignoremsk |= ST_BREAK;
3041 cor4 |= COR4_IGNBRK;
3044 portp->rxmarkmsk = ST_OVERRUN;
3045 if (tiosp->c_iflag & (INPCK | PARMRK))
3046 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3047 if (tiosp->c_iflag & BRKINT)
3048 portp->rxmarkmsk |= ST_BREAK;
3051 * Go through the char size, parity and stop bits and set all the
3052 * option register appropriately.
3054 switch (tiosp->c_cflag & CSIZE) {
3069 if (tiosp->c_cflag & CSTOPB)
3074 if (tiosp->c_cflag & PARENB) {
3075 if (tiosp->c_cflag & PARODD)
3076 cor1 |= (COR1_PARENB | COR1_PARODD);
3078 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3080 cor1 |= COR1_PARNONE;
3084 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3085 * space for hardware flow control and the like. This should be set to
3086 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3087 * really be based on VTIME.
3089 cor3 |= FIFO_RXTHRESHOLD;
3093 * Calculate the baud rate timers. For now we will just assume that
3094 * the input and output baud are the same. Could have used a baud
3095 * table here, but this way we can generate virtually any baud rate
3098 baudrate = tiosp->c_cflag & CBAUD;
3099 if (baudrate & CBAUDEX) {
3100 baudrate &= ~CBAUDEX;
3101 if ((baudrate < 1) || (baudrate > 4))
3102 tiosp->c_cflag &= ~CBAUDEX;
3106 baudrate = stl_baudrates[baudrate];
3107 if ((tiosp->c_cflag & CBAUD) == B38400) {
3108 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3110 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3112 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3114 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3116 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3117 baudrate = (portp->baud_base / portp->custom_divisor);
3119 if (baudrate > STL_CD1400MAXBAUD)
3120 baudrate = STL_CD1400MAXBAUD;
3123 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3124 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
3128 div = (unsigned char) clkdiv;
3132 * Check what form of modem signaling is required and set it up.
3134 if ((tiosp->c_cflag & CLOCAL) == 0) {
3137 sreron |= SRER_MODEM;
3138 portp->flags |= ASYNC_CHECK_CD;
3140 portp->flags &= ~ASYNC_CHECK_CD;
3144 * Setup cd1400 enhanced modes if we can. In particular we want to
3145 * handle as much of the flow control as possible automatically. As
3146 * well as saving a few CPU cycles it will also greatly improve flow
3147 * control reliability.
3149 if (tiosp->c_iflag & IXON) {
3152 if (tiosp->c_iflag & IXANY)
3156 if (tiosp->c_cflag & CRTSCTS) {
3158 mcor1 |= FIFO_RTSTHRESHOLD;
3162 * All cd1400 register values calculated so go through and set
3166 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3167 portp->portnr, portp->panelnr, portp->brdnr);
3168 pr_debug(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3169 cor1, cor2, cor3, cor4, cor5);
3170 pr_debug(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3171 mcor1, mcor2, rtpr, sreron, sreroff);
3172 pr_debug(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3173 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3174 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3175 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3177 spin_lock_irqsave(&brd_lock, flags);
3178 BRDENABLE(portp->brdnr, portp->pagenr);
3179 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3180 srer = stl_cd1400getreg(portp, SRER);
3181 stl_cd1400setreg(portp, SRER, 0);
3182 if (stl_cd1400updatereg(portp, COR1, cor1))
3184 if (stl_cd1400updatereg(portp, COR2, cor2))
3186 if (stl_cd1400updatereg(portp, COR3, cor3))
3189 stl_cd1400ccrwait(portp);
3190 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3192 stl_cd1400setreg(portp, COR4, cor4);
3193 stl_cd1400setreg(portp, COR5, cor5);
3194 stl_cd1400setreg(portp, MCOR1, mcor1);
3195 stl_cd1400setreg(portp, MCOR2, mcor2);
3197 stl_cd1400setreg(portp, TCOR, clk);
3198 stl_cd1400setreg(portp, TBPR, div);
3199 stl_cd1400setreg(portp, RCOR, clk);
3200 stl_cd1400setreg(portp, RBPR, div);
3202 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3203 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3204 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3205 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3206 stl_cd1400setreg(portp, RTPR, rtpr);
3207 mcor1 = stl_cd1400getreg(portp, MSVR1);
3208 if (mcor1 & MSVR1_DCD)
3209 portp->sigs |= TIOCM_CD;
3211 portp->sigs &= ~TIOCM_CD;
3212 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3213 BRDDISABLE(portp->brdnr);
3214 spin_unlock_irqrestore(&brd_lock, flags);
3217 /*****************************************************************************/
3220 * Set the state of the DTR and RTS signals.
3223 static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts)
3225 unsigned char msvr1, msvr2;
3226 unsigned long flags;
3228 pr_debug("stl_cd1400setsignals(portp=%p,dtr=%d,rts=%d)\n",
3238 spin_lock_irqsave(&brd_lock, flags);
3239 BRDENABLE(portp->brdnr, portp->pagenr);
3240 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3242 stl_cd1400setreg(portp, MSVR2, msvr2);
3244 stl_cd1400setreg(portp, MSVR1, msvr1);
3245 BRDDISABLE(portp->brdnr);
3246 spin_unlock_irqrestore(&brd_lock, flags);
3249 /*****************************************************************************/
3252 * Return the state of the signals.
3255 static int stl_cd1400getsignals(struct stlport *portp)
3257 unsigned char msvr1, msvr2;
3258 unsigned long flags;
3261 pr_debug("stl_cd1400getsignals(portp=%p)\n", portp);
3263 spin_lock_irqsave(&brd_lock, flags);
3264 BRDENABLE(portp->brdnr, portp->pagenr);
3265 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3266 msvr1 = stl_cd1400getreg(portp, MSVR1);
3267 msvr2 = stl_cd1400getreg(portp, MSVR2);
3268 BRDDISABLE(portp->brdnr);
3269 spin_unlock_irqrestore(&brd_lock, flags);
3272 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3273 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3274 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3275 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3277 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3278 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3285 /*****************************************************************************/
3288 * Enable/Disable the Transmitter and/or Receiver.
3291 static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx)
3294 unsigned long flags;
3296 pr_debug("stl_cd1400enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
3301 ccr |= CCR_TXDISABLE;
3303 ccr |= CCR_TXENABLE;
3305 ccr |= CCR_RXDISABLE;
3307 ccr |= CCR_RXENABLE;
3309 spin_lock_irqsave(&brd_lock, flags);
3310 BRDENABLE(portp->brdnr, portp->pagenr);
3311 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3312 stl_cd1400ccrwait(portp);
3313 stl_cd1400setreg(portp, CCR, ccr);
3314 stl_cd1400ccrwait(portp);
3315 BRDDISABLE(portp->brdnr);
3316 spin_unlock_irqrestore(&brd_lock, flags);
3319 /*****************************************************************************/
3322 * Start/stop the Transmitter and/or Receiver.
3325 static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx)
3327 unsigned char sreron, sreroff;
3328 unsigned long flags;
3330 pr_debug("stl_cd1400startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
3335 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3337 sreron |= SRER_TXDATA;
3339 sreron |= SRER_TXEMPTY;
3341 sreroff |= SRER_RXDATA;
3343 sreron |= SRER_RXDATA;
3345 spin_lock_irqsave(&brd_lock, flags);
3346 BRDENABLE(portp->brdnr, portp->pagenr);
3347 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3348 stl_cd1400setreg(portp, SRER,
3349 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3350 BRDDISABLE(portp->brdnr);
3352 set_bit(ASYI_TXBUSY, &portp->istate);
3353 spin_unlock_irqrestore(&brd_lock, flags);
3356 /*****************************************************************************/
3359 * Disable all interrupts from this port.
3362 static void stl_cd1400disableintrs(struct stlport *portp)
3364 unsigned long flags;
3366 pr_debug("stl_cd1400disableintrs(portp=%p)\n", portp);
3368 spin_lock_irqsave(&brd_lock, flags);
3369 BRDENABLE(portp->brdnr, portp->pagenr);
3370 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3371 stl_cd1400setreg(portp, SRER, 0);
3372 BRDDISABLE(portp->brdnr);
3373 spin_unlock_irqrestore(&brd_lock, flags);
3376 /*****************************************************************************/
3378 static void stl_cd1400sendbreak(struct stlport *portp, int len)
3380 unsigned long flags;
3382 pr_debug("stl_cd1400sendbreak(portp=%p,len=%d)\n", portp, len);
3384 spin_lock_irqsave(&brd_lock, flags);
3385 BRDENABLE(portp->brdnr, portp->pagenr);
3386 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3387 stl_cd1400setreg(portp, SRER,
3388 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3390 BRDDISABLE(portp->brdnr);
3391 portp->brklen = len;
3393 portp->stats.txbreaks++;
3394 spin_unlock_irqrestore(&brd_lock, flags);
3397 /*****************************************************************************/
3400 * Take flow control actions...
3403 static void stl_cd1400flowctrl(struct stlport *portp, int state)
3405 struct tty_struct *tty;
3406 unsigned long flags;
3408 pr_debug("stl_cd1400flowctrl(portp=%p,state=%x)\n", portp, state);
3416 spin_lock_irqsave(&brd_lock, flags);
3417 BRDENABLE(portp->brdnr, portp->pagenr);
3418 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3421 if (tty->termios->c_iflag & IXOFF) {
3422 stl_cd1400ccrwait(portp);
3423 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3424 portp->stats.rxxon++;
3425 stl_cd1400ccrwait(portp);
3428 * Question: should we return RTS to what it was before? It may
3429 * have been set by an ioctl... Suppose not, since if you have
3430 * hardware flow control set then it is pretty silly to go and
3431 * set the RTS line by hand.
3433 if (tty->termios->c_cflag & CRTSCTS) {
3434 stl_cd1400setreg(portp, MCOR1,
3435 (stl_cd1400getreg(portp, MCOR1) |
3436 FIFO_RTSTHRESHOLD));
3437 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3438 portp->stats.rxrtson++;
3441 if (tty->termios->c_iflag & IXOFF) {
3442 stl_cd1400ccrwait(portp);
3443 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3444 portp->stats.rxxoff++;
3445 stl_cd1400ccrwait(portp);
3447 if (tty->termios->c_cflag & CRTSCTS) {
3448 stl_cd1400setreg(portp, MCOR1,
3449 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3450 stl_cd1400setreg(portp, MSVR2, 0);
3451 portp->stats.rxrtsoff++;
3455 BRDDISABLE(portp->brdnr);
3456 spin_unlock_irqrestore(&brd_lock, flags);
3459 /*****************************************************************************/
3462 * Send a flow control character...
3465 static void stl_cd1400sendflow(struct stlport *portp, int state)
3467 struct tty_struct *tty;
3468 unsigned long flags;
3470 pr_debug("stl_cd1400sendflow(portp=%p,state=%x)\n", portp, state);
3478 spin_lock_irqsave(&brd_lock, flags);
3479 BRDENABLE(portp->brdnr, portp->pagenr);
3480 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3482 stl_cd1400ccrwait(portp);
3483 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3484 portp->stats.rxxon++;
3485 stl_cd1400ccrwait(portp);
3487 stl_cd1400ccrwait(portp);
3488 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3489 portp->stats.rxxoff++;
3490 stl_cd1400ccrwait(portp);
3492 BRDDISABLE(portp->brdnr);
3493 spin_unlock_irqrestore(&brd_lock, flags);
3496 /*****************************************************************************/
3498 static void stl_cd1400flush(struct stlport *portp)
3500 unsigned long flags;
3502 pr_debug("stl_cd1400flush(portp=%p)\n", portp);
3507 spin_lock_irqsave(&brd_lock, flags);
3508 BRDENABLE(portp->brdnr, portp->pagenr);
3509 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3510 stl_cd1400ccrwait(portp);
3511 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3512 stl_cd1400ccrwait(portp);
3513 portp->tx.tail = portp->tx.head;
3514 BRDDISABLE(portp->brdnr);
3515 spin_unlock_irqrestore(&brd_lock, flags);
3518 /*****************************************************************************/
3521 * Return the current state of data flow on this port. This is only
3522 * really interresting when determining if data has fully completed
3523 * transmission or not... This is easy for the cd1400, it accurately
3524 * maintains the busy port flag.
3527 static int stl_cd1400datastate(struct stlport *portp)
3529 pr_debug("stl_cd1400datastate(portp=%p)\n", portp);
3534 return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
3537 /*****************************************************************************/
3540 * Interrupt service routine for cd1400 EasyIO boards.
3543 static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase)
3545 unsigned char svrtype;
3547 pr_debug("stl_cd1400eiointr(panelp=%p,iobase=%x)\n", panelp, iobase);
3549 spin_lock(&brd_lock);
3551 svrtype = inb(iobase + EREG_DATA);
3552 if (panelp->nrports > 4) {
3553 outb((SVRR + 0x80), iobase);
3554 svrtype |= inb(iobase + EREG_DATA);
3557 if (svrtype & SVRR_RX)
3558 stl_cd1400rxisr(panelp, iobase);
3559 else if (svrtype & SVRR_TX)
3560 stl_cd1400txisr(panelp, iobase);
3561 else if (svrtype & SVRR_MDM)
3562 stl_cd1400mdmisr(panelp, iobase);
3564 spin_unlock(&brd_lock);
3567 /*****************************************************************************/
3570 * Interrupt service routine for cd1400 panels.
3573 static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase)
3575 unsigned char svrtype;
3577 pr_debug("stl_cd1400echintr(panelp=%p,iobase=%x)\n", panelp, iobase);
3580 svrtype = inb(iobase + EREG_DATA);
3581 outb((SVRR + 0x80), iobase);
3582 svrtype |= inb(iobase + EREG_DATA);
3583 if (svrtype & SVRR_RX)
3584 stl_cd1400rxisr(panelp, iobase);
3585 else if (svrtype & SVRR_TX)
3586 stl_cd1400txisr(panelp, iobase);
3587 else if (svrtype & SVRR_MDM)
3588 stl_cd1400mdmisr(panelp, iobase);
3592 /*****************************************************************************/
3595 * Unfortunately we need to handle breaks in the TX data stream, since
3596 * this is the only way to generate them on the cd1400.
3599 static inline int stl_cd1400breakisr(struct stlport *portp, int ioaddr)
3601 if (portp->brklen == 1) {
3602 outb((COR2 + portp->uartaddr), ioaddr);
3603 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
3604 (ioaddr + EREG_DATA));
3605 outb((TDR + portp->uartaddr), ioaddr);
3606 outb(ETC_CMD, (ioaddr + EREG_DATA));
3607 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
3608 outb((SRER + portp->uartaddr), ioaddr);
3609 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
3610 (ioaddr + EREG_DATA));
3612 } else if (portp->brklen > 1) {
3613 outb((TDR + portp->uartaddr), ioaddr);
3614 outb(ETC_CMD, (ioaddr + EREG_DATA));
3615 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
3619 outb((COR2 + portp->uartaddr), ioaddr);
3620 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
3621 (ioaddr + EREG_DATA));
3627 /*****************************************************************************/
3630 * Transmit interrupt handler. This has gotta be fast! Handling TX
3631 * chars is pretty simple, stuff as many as possible from the TX buffer
3632 * into the cd1400 FIFO. Must also handle TX breaks here, since they
3633 * are embedded as commands in the data stream. Oh no, had to use a goto!
3634 * This could be optimized more, will do when I get time...
3635 * In practice it is possible that interrupts are enabled but that the
3636 * port has been hung up. Need to handle not having any TX buffer here,
3637 * this is done by using the side effect that head and tail will also
3638 * be NULL if the buffer has been freed.
3641 static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr)
3643 struct stlport *portp;
3646 unsigned char ioack, srer;
3648 pr_debug("stl_cd1400txisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3650 ioack = inb(ioaddr + EREG_TXACK);
3651 if (((ioack & panelp->ackmask) != 0) ||
3652 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
3653 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
3656 portp = panelp->ports[(ioack >> 3)];
3659 * Unfortunately we need to handle breaks in the data stream, since
3660 * this is the only way to generate them on the cd1400. Do it now if
3661 * a break is to be sent.
3663 if (portp->brklen != 0)
3664 if (stl_cd1400breakisr(portp, ioaddr))
3667 head = portp->tx.head;
3668 tail = portp->tx.tail;
3669 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
3670 if ((len == 0) || ((len < STL_TXBUFLOW) &&
3671 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
3672 set_bit(ASYI_TXLOW, &portp->istate);
3673 schedule_work(&portp->tqueue);
3677 outb((SRER + portp->uartaddr), ioaddr);
3678 srer = inb(ioaddr + EREG_DATA);
3679 if (srer & SRER_TXDATA) {
3680 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
3682 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
3683 clear_bit(ASYI_TXBUSY, &portp->istate);
3685 outb(srer, (ioaddr + EREG_DATA));
3687 len = MIN(len, CD1400_TXFIFOSIZE);
3688 portp->stats.txtotal += len;
3689 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
3690 outb((TDR + portp->uartaddr), ioaddr);
3691 outsb((ioaddr + EREG_DATA), tail, stlen);
3694 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
3695 tail = portp->tx.buf;
3697 outsb((ioaddr + EREG_DATA), tail, len);
3700 portp->tx.tail = tail;
3704 outb((EOSRR + portp->uartaddr), ioaddr);
3705 outb(0, (ioaddr + EREG_DATA));
3708 /*****************************************************************************/
3711 * Receive character interrupt handler. Determine if we have good chars
3712 * or bad chars and then process appropriately. Good chars are easy
3713 * just shove the lot into the RX buffer and set all status byte to 0.
3714 * If a bad RX char then process as required. This routine needs to be
3715 * fast! In practice it is possible that we get an interrupt on a port
3716 * that is closed. This can happen on hangups - since they completely
3717 * shutdown a port not in user context. Need to handle this case.
3720 static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr)
3722 struct stlport *portp;
3723 struct tty_struct *tty;
3724 unsigned int ioack, len, buflen;
3725 unsigned char status;
3728 pr_debug("stl_cd1400rxisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3730 ioack = inb(ioaddr + EREG_RXACK);
3731 if ((ioack & panelp->ackmask) != 0) {
3732 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
3735 portp = panelp->ports[(ioack >> 3)];
3738 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
3739 outb((RDCR + portp->uartaddr), ioaddr);
3740 len = inb(ioaddr + EREG_DATA);
3741 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
3742 len = MIN(len, sizeof(stl_unwanted));
3743 outb((RDSR + portp->uartaddr), ioaddr);
3744 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
3745 portp->stats.rxlost += len;
3746 portp->stats.rxtotal += len;
3748 len = MIN(len, buflen);
3751 outb((RDSR + portp->uartaddr), ioaddr);
3752 tty_prepare_flip_string(tty, &ptr, len);
3753 insb((ioaddr + EREG_DATA), ptr, len);
3754 tty_schedule_flip(tty);
3755 portp->stats.rxtotal += len;
3758 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
3759 outb((RDSR + portp->uartaddr), ioaddr);
3760 status = inb(ioaddr + EREG_DATA);
3761 ch = inb(ioaddr + EREG_DATA);
3762 if (status & ST_PARITY)
3763 portp->stats.rxparity++;
3764 if (status & ST_FRAMING)
3765 portp->stats.rxframing++;
3766 if (status & ST_OVERRUN)
3767 portp->stats.rxoverrun++;
3768 if (status & ST_BREAK)
3769 portp->stats.rxbreaks++;
3770 if (status & ST_SCHARMASK) {
3771 if ((status & ST_SCHARMASK) == ST_SCHAR1)
3772 portp->stats.txxon++;
3773 if ((status & ST_SCHARMASK) == ST_SCHAR2)
3774 portp->stats.txxoff++;
3777 if (tty != NULL && (portp->rxignoremsk & status) == 0) {
3778 if (portp->rxmarkmsk & status) {
3779 if (status & ST_BREAK) {
3781 if (portp->flags & ASYNC_SAK) {
3783 BRDENABLE(portp->brdnr, portp->pagenr);
3785 } else if (status & ST_PARITY) {
3786 status = TTY_PARITY;
3787 } else if (status & ST_FRAMING) {
3789 } else if(status & ST_OVERRUN) {
3790 status = TTY_OVERRUN;
3797 tty_insert_flip_char(tty, ch, status);
3798 tty_schedule_flip(tty);
3801 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
3806 outb((EOSRR + portp->uartaddr), ioaddr);
3807 outb(0, (ioaddr + EREG_DATA));
3810 /*****************************************************************************/
3813 * Modem interrupt handler. The is called when the modem signal line
3814 * (DCD) has changed state. Leave most of the work to the off-level
3815 * processing routine.
3818 static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr)
3820 struct stlport *portp;
3824 pr_debug("stl_cd1400mdmisr(panelp=%p)\n", panelp);
3826 ioack = inb(ioaddr + EREG_MDACK);
3827 if (((ioack & panelp->ackmask) != 0) ||
3828 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
3829 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
3832 portp = panelp->ports[(ioack >> 3)];
3834 outb((MISR + portp->uartaddr), ioaddr);
3835 misr = inb(ioaddr + EREG_DATA);
3836 if (misr & MISR_DCD) {
3837 set_bit(ASYI_DCDCHANGE, &portp->istate);
3838 schedule_work(&portp->tqueue);
3839 portp->stats.modem++;
3842 outb((EOSRR + portp->uartaddr), ioaddr);
3843 outb(0, (ioaddr + EREG_DATA));
3846 /*****************************************************************************/
3847 /* SC26198 HARDWARE FUNCTIONS */
3848 /*****************************************************************************/
3851 * These functions get/set/update the registers of the sc26198 UARTs.
3852 * Access to the sc26198 registers is via an address/data io port pair.
3853 * (Maybe should make this inline...)
3856 static int stl_sc26198getreg(struct stlport *portp, int regnr)
3858 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3859 return inb(portp->ioaddr + XP_DATA);
3862 static void stl_sc26198setreg(struct stlport *portp, int regnr, int value)
3864 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3865 outb(value, (portp->ioaddr + XP_DATA));
3868 static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value)
3870 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3871 if (inb(portp->ioaddr + XP_DATA) != value) {
3872 outb(value, (portp->ioaddr + XP_DATA));
3878 /*****************************************************************************/
3881 * Functions to get and set the sc26198 global registers.
3884 static int stl_sc26198getglobreg(struct stlport *portp, int regnr)
3886 outb(regnr, (portp->ioaddr + XP_ADDR));
3887 return inb(portp->ioaddr + XP_DATA);
3891 static void stl_sc26198setglobreg(struct stlport *portp, int regnr, int value)
3893 outb(regnr, (portp->ioaddr + XP_ADDR));
3894 outb(value, (portp->ioaddr + XP_DATA));
3898 /*****************************************************************************/
3901 * Inbitialize the UARTs in a panel. We don't care what sort of board
3902 * these ports are on - since the port io registers are almost
3903 * identical when dealing with ports.
3906 static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
3909 int nrchips, ioaddr;
3911 pr_debug("stl_sc26198panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
3913 BRDENABLE(panelp->brdnr, panelp->pagenr);
3916 * Check that each chip is present and started up OK.
3919 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
3920 if (brdp->brdtype == BRD_ECHPCI)
3921 outb(panelp->pagenr, brdp->ioctrl);
3923 for (i = 0; (i < nrchips); i++) {
3924 ioaddr = panelp->iobase + (i * 4);
3925 outb(SCCR, (ioaddr + XP_ADDR));
3926 outb(CR_RESETALL, (ioaddr + XP_DATA));
3927 outb(TSTR, (ioaddr + XP_ADDR));
3928 if (inb(ioaddr + XP_DATA) != 0) {
3929 printk("STALLION: sc26198 not responding, "
3930 "brd=%d panel=%d chip=%d\n",
3931 panelp->brdnr, panelp->panelnr, i);
3934 chipmask |= (0x1 << i);
3935 outb(GCCR, (ioaddr + XP_ADDR));
3936 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
3937 outb(WDTRCR, (ioaddr + XP_ADDR));
3938 outb(0xff, (ioaddr + XP_DATA));
3941 BRDDISABLE(panelp->brdnr);
3945 /*****************************************************************************/
3948 * Initialize hardware specific port registers.
3951 static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
3953 pr_debug("stl_sc26198portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
3956 if ((brdp == NULL) || (panelp == NULL) ||
3960 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
3961 portp->uartaddr = (portp->portnr & 0x07) << 4;
3962 portp->pagenr = panelp->pagenr;
3965 BRDENABLE(portp->brdnr, portp->pagenr);
3966 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
3967 BRDDISABLE(portp->brdnr);
3970 /*****************************************************************************/
3973 * Set up the sc26198 registers for a port based on the termios port
3977 static void stl_sc26198setport(struct stlport *portp, struct termios *tiosp)
3979 struct stlbrd *brdp;
3980 unsigned long flags;
3981 unsigned int baudrate;
3982 unsigned char mr0, mr1, mr2, clk;
3983 unsigned char imron, imroff, iopr, ipr;
3993 brdp = stl_brds[portp->brdnr];
3998 * Set up the RX char ignore mask with those RX error types we
4001 portp->rxignoremsk = 0;
4002 if (tiosp->c_iflag & IGNPAR)
4003 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
4005 if (tiosp->c_iflag & IGNBRK)
4006 portp->rxignoremsk |= SR_RXBREAK;
4008 portp->rxmarkmsk = SR_RXOVERRUN;
4009 if (tiosp->c_iflag & (INPCK | PARMRK))
4010 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
4011 if (tiosp->c_iflag & BRKINT)
4012 portp->rxmarkmsk |= SR_RXBREAK;
4015 * Go through the char size, parity and stop bits and set all the
4016 * option register appropriately.
4018 switch (tiosp->c_cflag & CSIZE) {
4033 if (tiosp->c_cflag & CSTOPB)
4038 if (tiosp->c_cflag & PARENB) {
4039 if (tiosp->c_cflag & PARODD)
4040 mr1 |= (MR1_PARENB | MR1_PARODD);
4042 mr1 |= (MR1_PARENB | MR1_PAREVEN);
4047 mr1 |= MR1_ERRBLOCK;
4050 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4051 * space for hardware flow control and the like. This should be set to
4054 mr2 |= MR2_RXFIFOHALF;
4057 * Calculate the baud rate timers. For now we will just assume that
4058 * the input and output baud are the same. The sc26198 has a fixed
4059 * baud rate table, so only discrete baud rates possible.
4061 baudrate = tiosp->c_cflag & CBAUD;
4062 if (baudrate & CBAUDEX) {
4063 baudrate &= ~CBAUDEX;
4064 if ((baudrate < 1) || (baudrate > 4))
4065 tiosp->c_cflag &= ~CBAUDEX;
4069 baudrate = stl_baudrates[baudrate];
4070 if ((tiosp->c_cflag & CBAUD) == B38400) {
4071 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
4073 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
4075 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
4077 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
4079 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
4080 baudrate = (portp->baud_base / portp->custom_divisor);
4082 if (baudrate > STL_SC26198MAXBAUD)
4083 baudrate = STL_SC26198MAXBAUD;
4086 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
4087 if (baudrate <= sc26198_baudtable[clk])
4093 * Check what form of modem signaling is required and set it up.
4095 if (tiosp->c_cflag & CLOCAL) {
4096 portp->flags &= ~ASYNC_CHECK_CD;
4098 iopr |= IOPR_DCDCOS;
4100 portp->flags |= ASYNC_CHECK_CD;
4104 * Setup sc26198 enhanced modes if we can. In particular we want to
4105 * handle as much of the flow control as possible automatically. As
4106 * well as saving a few CPU cycles it will also greatly improve flow
4107 * control reliability.
4109 if (tiosp->c_iflag & IXON) {
4110 mr0 |= MR0_SWFTX | MR0_SWFT;
4111 imron |= IR_XONXOFF;
4113 imroff |= IR_XONXOFF;
4115 if (tiosp->c_iflag & IXOFF)
4118 if (tiosp->c_cflag & CRTSCTS) {
4124 * All sc26198 register values calculated so go through and set
4128 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4129 portp->portnr, portp->panelnr, portp->brdnr);
4130 pr_debug(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4131 pr_debug(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4132 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4133 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4134 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4136 spin_lock_irqsave(&brd_lock, flags);
4137 BRDENABLE(portp->brdnr, portp->pagenr);
4138 stl_sc26198setreg(portp, IMR, 0);
4139 stl_sc26198updatereg(portp, MR0, mr0);
4140 stl_sc26198updatereg(portp, MR1, mr1);
4141 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4142 stl_sc26198updatereg(portp, MR2, mr2);
4143 stl_sc26198updatereg(portp, IOPIOR,
4144 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
4147 stl_sc26198setreg(portp, TXCSR, clk);
4148 stl_sc26198setreg(portp, RXCSR, clk);
4151 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4152 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4154 ipr = stl_sc26198getreg(portp, IPR);
4156 portp->sigs &= ~TIOCM_CD;
4158 portp->sigs |= TIOCM_CD;
4160 portp->imr = (portp->imr & ~imroff) | imron;
4161 stl_sc26198setreg(portp, IMR, portp->imr);
4162 BRDDISABLE(portp->brdnr);
4163 spin_unlock_irqrestore(&brd_lock, flags);
4166 /*****************************************************************************/
4169 * Set the state of the DTR and RTS signals.
4172 static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts)
4174 unsigned char iopioron, iopioroff;
4175 unsigned long flags;
4177 pr_debug("stl_sc26198setsignals(portp=%p,dtr=%d,rts=%d)\n", portp,
4183 iopioroff |= IPR_DTR;
4185 iopioron |= IPR_DTR;
4187 iopioroff |= IPR_RTS;
4189 iopioron |= IPR_RTS;
4191 spin_lock_irqsave(&brd_lock, flags);
4192 BRDENABLE(portp->brdnr, portp->pagenr);
4193 stl_sc26198setreg(portp, IOPIOR,
4194 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4195 BRDDISABLE(portp->brdnr);
4196 spin_unlock_irqrestore(&brd_lock, flags);
4199 /*****************************************************************************/
4202 * Return the state of the signals.
4205 static int stl_sc26198getsignals(struct stlport *portp)
4208 unsigned long flags;
4211 pr_debug("stl_sc26198getsignals(portp=%p)\n", portp);
4213 spin_lock_irqsave(&brd_lock, flags);
4214 BRDENABLE(portp->brdnr, portp->pagenr);
4215 ipr = stl_sc26198getreg(portp, IPR);
4216 BRDDISABLE(portp->brdnr);
4217 spin_unlock_irqrestore(&brd_lock, flags);
4220 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4221 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4222 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4223 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4228 /*****************************************************************************/
4231 * Enable/Disable the Transmitter and/or Receiver.
4234 static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx)
4237 unsigned long flags;
4239 pr_debug("stl_sc26198enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx,tx);
4241 ccr = portp->crenable;
4243 ccr &= ~CR_TXENABLE;
4247 ccr &= ~CR_RXENABLE;
4251 spin_lock_irqsave(&brd_lock, flags);
4252 BRDENABLE(portp->brdnr, portp->pagenr);
4253 stl_sc26198setreg(portp, SCCR, ccr);
4254 BRDDISABLE(portp->brdnr);
4255 portp->crenable = ccr;
4256 spin_unlock_irqrestore(&brd_lock, flags);
4259 /*****************************************************************************/
4262 * Start/stop the Transmitter and/or Receiver.
4265 static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx)
4268 unsigned long flags;
4270 pr_debug("stl_sc26198startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
4278 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4280 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4282 spin_lock_irqsave(&brd_lock, flags);
4283 BRDENABLE(portp->brdnr, portp->pagenr);
4284 stl_sc26198setreg(portp, IMR, imr);
4285 BRDDISABLE(portp->brdnr);
4288 set_bit(ASYI_TXBUSY, &portp->istate);
4289 spin_unlock_irqrestore(&brd_lock, flags);
4292 /*****************************************************************************/
4295 * Disable all interrupts from this port.
4298 static void stl_sc26198disableintrs(struct stlport *portp)
4300 unsigned long flags;
4302 pr_debug("stl_sc26198disableintrs(portp=%p)\n", portp);
4304 spin_lock_irqsave(&brd_lock, flags);
4305 BRDENABLE(portp->brdnr, portp->pagenr);
4307 stl_sc26198setreg(portp, IMR, 0);
4308 BRDDISABLE(portp->brdnr);
4309 spin_unlock_irqrestore(&brd_lock, flags);
4312 /*****************************************************************************/
4314 static void stl_sc26198sendbreak(struct stlport *portp, int len)
4316 unsigned long flags;
4318 pr_debug("stl_sc26198sendbreak(portp=%p,len=%d)\n", portp, len);
4320 spin_lock_irqsave(&brd_lock, flags);
4321 BRDENABLE(portp->brdnr, portp->pagenr);
4323 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4324 portp->stats.txbreaks++;
4326 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4328 BRDDISABLE(portp->brdnr);
4329 spin_unlock_irqrestore(&brd_lock, flags);
4332 /*****************************************************************************/
4335 * Take flow control actions...
4338 static void stl_sc26198flowctrl(struct stlport *portp, int state)
4340 struct tty_struct *tty;
4341 unsigned long flags;
4344 pr_debug("stl_sc26198flowctrl(portp=%p,state=%x)\n", portp, state);
4352 spin_lock_irqsave(&brd_lock, flags);
4353 BRDENABLE(portp->brdnr, portp->pagenr);
4356 if (tty->termios->c_iflag & IXOFF) {
4357 mr0 = stl_sc26198getreg(portp, MR0);
4358 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4359 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4361 portp->stats.rxxon++;
4362 stl_sc26198wait(portp);
4363 stl_sc26198setreg(portp, MR0, mr0);
4366 * Question: should we return RTS to what it was before? It may
4367 * have been set by an ioctl... Suppose not, since if you have
4368 * hardware flow control set then it is pretty silly to go and
4369 * set the RTS line by hand.
4371 if (tty->termios->c_cflag & CRTSCTS) {
4372 stl_sc26198setreg(portp, MR1,
4373 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4374 stl_sc26198setreg(portp, IOPIOR,
4375 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4376 portp->stats.rxrtson++;
4379 if (tty->termios->c_iflag & IXOFF) {
4380 mr0 = stl_sc26198getreg(portp, MR0);
4381 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4382 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4384 portp->stats.rxxoff++;
4385 stl_sc26198wait(portp);
4386 stl_sc26198setreg(portp, MR0, mr0);
4388 if (tty->termios->c_cflag & CRTSCTS) {
4389 stl_sc26198setreg(portp, MR1,
4390 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4391 stl_sc26198setreg(portp, IOPIOR,
4392 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4393 portp->stats.rxrtsoff++;
4397 BRDDISABLE(portp->brdnr);
4398 spin_unlock_irqrestore(&brd_lock, flags);
4401 /*****************************************************************************/
4404 * Send a flow control character.
4407 static void stl_sc26198sendflow(struct stlport *portp, int state)
4409 struct tty_struct *tty;
4410 unsigned long flags;
4413 pr_debug("stl_sc26198sendflow(portp=%p,state=%x)\n", portp, state);
4421 spin_lock_irqsave(&brd_lock, flags);
4422 BRDENABLE(portp->brdnr, portp->pagenr);
4424 mr0 = stl_sc26198getreg(portp, MR0);
4425 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4426 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4428 portp->stats.rxxon++;
4429 stl_sc26198wait(portp);
4430 stl_sc26198setreg(portp, MR0, mr0);
4432 mr0 = stl_sc26198getreg(portp, MR0);
4433 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4434 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4436 portp->stats.rxxoff++;
4437 stl_sc26198wait(portp);
4438 stl_sc26198setreg(portp, MR0, mr0);
4440 BRDDISABLE(portp->brdnr);
4441 spin_unlock_irqrestore(&brd_lock, flags);
4444 /*****************************************************************************/
4446 static void stl_sc26198flush(struct stlport *portp)
4448 unsigned long flags;
4450 pr_debug("stl_sc26198flush(portp=%p)\n", portp);
4455 spin_lock_irqsave(&brd_lock, flags);
4456 BRDENABLE(portp->brdnr, portp->pagenr);
4457 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4458 stl_sc26198setreg(portp, SCCR, portp->crenable);
4459 BRDDISABLE(portp->brdnr);
4460 portp->tx.tail = portp->tx.head;
4461 spin_unlock_irqrestore(&brd_lock, flags);
4464 /*****************************************************************************/
4467 * Return the current state of data flow on this port. This is only
4468 * really interresting when determining if data has fully completed
4469 * transmission or not... The sc26198 interrupt scheme cannot
4470 * determine when all data has actually drained, so we need to
4471 * check the port statusy register to be sure.
4474 static int stl_sc26198datastate(struct stlport *portp)
4476 unsigned long flags;
4479 pr_debug("stl_sc26198datastate(portp=%p)\n", portp);
4483 if (test_bit(ASYI_TXBUSY, &portp->istate))
4486 spin_lock_irqsave(&brd_lock, flags);
4487 BRDENABLE(portp->brdnr, portp->pagenr);
4488 sr = stl_sc26198getreg(portp, SR);
4489 BRDDISABLE(portp->brdnr);
4490 spin_unlock_irqrestore(&brd_lock, flags);
4492 return (sr & SR_TXEMPTY) ? 0 : 1;
4495 /*****************************************************************************/
4498 * Delay for a small amount of time, to give the sc26198 a chance
4499 * to process a command...
4502 static void stl_sc26198wait(struct stlport *portp)
4506 pr_debug("stl_sc26198wait(portp=%p)\n", portp);
4511 for (i = 0; (i < 20); i++)
4512 stl_sc26198getglobreg(portp, TSTR);
4515 /*****************************************************************************/
4518 * If we are TX flow controlled and in IXANY mode then we may
4519 * need to unflow control here. We gotta do this because of the
4520 * automatic flow control modes of the sc26198.
4523 static inline void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty)
4527 mr0 = stl_sc26198getreg(portp, MR0);
4528 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4529 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4530 stl_sc26198wait(portp);
4531 stl_sc26198setreg(portp, MR0, mr0);
4532 clear_bit(ASYI_TXFLOWED, &portp->istate);
4535 /*****************************************************************************/
4538 * Interrupt service routine for sc26198 panels.
4541 static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase)
4543 struct stlport *portp;
4546 spin_lock(&brd_lock);
4549 * Work around bug in sc26198 chip... Cannot have A6 address
4550 * line of UART high, else iack will be returned as 0.
4552 outb(0, (iobase + 1));
4554 iack = inb(iobase + XP_IACK);
4555 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4557 if (iack & IVR_RXDATA)
4558 stl_sc26198rxisr(portp, iack);
4559 else if (iack & IVR_TXDATA)
4560 stl_sc26198txisr(portp);
4562 stl_sc26198otherisr(portp, iack);
4564 spin_unlock(&brd_lock);
4567 /*****************************************************************************/
4570 * Transmit interrupt handler. This has gotta be fast! Handling TX
4571 * chars is pretty simple, stuff as many as possible from the TX buffer
4572 * into the sc26198 FIFO.
4573 * In practice it is possible that interrupts are enabled but that the
4574 * port has been hung up. Need to handle not having any TX buffer here,
4575 * this is done by using the side effect that head and tail will also
4576 * be NULL if the buffer has been freed.
4579 static void stl_sc26198txisr(struct stlport *portp)
4581 unsigned int ioaddr;
4586 pr_debug("stl_sc26198txisr(portp=%p)\n", portp);
4588 ioaddr = portp->ioaddr;
4589 head = portp->tx.head;
4590 tail = portp->tx.tail;
4591 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4592 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4593 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4594 set_bit(ASYI_TXLOW, &portp->istate);
4595 schedule_work(&portp->tqueue);
4599 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
4600 mr0 = inb(ioaddr + XP_DATA);
4601 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4602 portp->imr &= ~IR_TXRDY;
4603 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
4604 outb(portp->imr, (ioaddr + XP_DATA));
4605 clear_bit(ASYI_TXBUSY, &portp->istate);
4607 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4608 outb(mr0, (ioaddr + XP_DATA));
4611 len = MIN(len, SC26198_TXFIFOSIZE);
4612 portp->stats.txtotal += len;
4613 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4614 outb(GTXFIFO, (ioaddr + XP_ADDR));
4615 outsb((ioaddr + XP_DATA), tail, stlen);
4618 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4619 tail = portp->tx.buf;
4621 outsb((ioaddr + XP_DATA), tail, len);
4624 portp->tx.tail = tail;
4628 /*****************************************************************************/
4631 * Receive character interrupt handler. Determine if we have good chars
4632 * or bad chars and then process appropriately. Good chars are easy
4633 * just shove the lot into the RX buffer and set all status byte to 0.
4634 * If a bad RX char then process as required. This routine needs to be
4635 * fast! In practice it is possible that we get an interrupt on a port
4636 * that is closed. This can happen on hangups - since they completely
4637 * shutdown a port not in user context. Need to handle this case.
4640 static void stl_sc26198rxisr(struct stlport *portp, unsigned int iack)
4642 struct tty_struct *tty;
4643 unsigned int len, buflen, ioaddr;
4645 pr_debug("stl_sc26198rxisr(portp=%p,iack=%x)\n", portp, iack);
4648 ioaddr = portp->ioaddr;
4649 outb(GIBCR, (ioaddr + XP_ADDR));
4650 len = inb(ioaddr + XP_DATA) + 1;
4652 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
4653 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
4654 len = MIN(len, sizeof(stl_unwanted));
4655 outb(GRXFIFO, (ioaddr + XP_ADDR));
4656 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4657 portp->stats.rxlost += len;
4658 portp->stats.rxtotal += len;
4660 len = MIN(len, buflen);
4663 outb(GRXFIFO, (ioaddr + XP_ADDR));
4664 tty_prepare_flip_string(tty, &ptr, len);
4665 insb((ioaddr + XP_DATA), ptr, len);
4666 tty_schedule_flip(tty);
4667 portp->stats.rxtotal += len;
4671 stl_sc26198rxbadchars(portp);
4675 * If we are TX flow controlled and in IXANY mode then we may need
4676 * to unflow control here. We gotta do this because of the automatic
4677 * flow control modes of the sc26198.
4679 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
4680 if ((tty != NULL) &&
4681 (tty->termios != NULL) &&
4682 (tty->termios->c_iflag & IXANY)) {
4683 stl_sc26198txunflow(portp, tty);
4688 /*****************************************************************************/
4691 * Process an RX bad character.
4694 static inline void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch)
4696 struct tty_struct *tty;
4697 unsigned int ioaddr;
4700 ioaddr = portp->ioaddr;
4702 if (status & SR_RXPARITY)
4703 portp->stats.rxparity++;
4704 if (status & SR_RXFRAMING)
4705 portp->stats.rxframing++;
4706 if (status & SR_RXOVERRUN)
4707 portp->stats.rxoverrun++;
4708 if (status & SR_RXBREAK)
4709 portp->stats.rxbreaks++;
4711 if ((tty != NULL) &&
4712 ((portp->rxignoremsk & status) == 0)) {
4713 if (portp->rxmarkmsk & status) {
4714 if (status & SR_RXBREAK) {
4716 if (portp->flags & ASYNC_SAK) {
4718 BRDENABLE(portp->brdnr, portp->pagenr);
4720 } else if (status & SR_RXPARITY) {
4721 status = TTY_PARITY;
4722 } else if (status & SR_RXFRAMING) {
4724 } else if(status & SR_RXOVERRUN) {
4725 status = TTY_OVERRUN;
4733 tty_insert_flip_char(tty, ch, status);
4734 tty_schedule_flip(tty);
4737 portp->stats.rxtotal++;
4741 /*****************************************************************************/
4744 * Process all characters in the RX FIFO of the UART. Check all char
4745 * status bytes as well, and process as required. We need to check
4746 * all bytes in the FIFO, in case some more enter the FIFO while we
4747 * are here. To get the exact character error type we need to switch
4748 * into CHAR error mode (that is why we need to make sure we empty
4752 static void stl_sc26198rxbadchars(struct stlport *portp)
4754 unsigned char status, mr1;
4758 * To get the precise error type for each character we must switch
4759 * back into CHAR error mode.
4761 mr1 = stl_sc26198getreg(portp, MR1);
4762 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
4764 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
4765 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
4766 ch = stl_sc26198getreg(portp, RXFIFO);
4767 stl_sc26198rxbadch(portp, status, ch);
4771 * To get correct interrupt class we must switch back into BLOCK
4774 stl_sc26198setreg(portp, MR1, mr1);
4777 /*****************************************************************************/
4780 * Other interrupt handler. This includes modem signals, flow
4781 * control actions, etc. Most stuff is left to off-level interrupt
4785 static void stl_sc26198otherisr(struct stlport *portp, unsigned int iack)
4787 unsigned char cir, ipr, xisr;
4789 pr_debug("stl_sc26198otherisr(portp=%p,iack=%x)\n", portp, iack);
4791 cir = stl_sc26198getglobreg(portp, CIR);
4793 switch (cir & CIR_SUBTYPEMASK) {
4795 ipr = stl_sc26198getreg(portp, IPR);
4796 if (ipr & IPR_DCDCHANGE) {
4797 set_bit(ASYI_DCDCHANGE, &portp->istate);
4798 schedule_work(&portp->tqueue);
4799 portp->stats.modem++;
4802 case CIR_SUBXONXOFF:
4803 xisr = stl_sc26198getreg(portp, XISR);
4804 if (xisr & XISR_RXXONGOT) {
4805 set_bit(ASYI_TXFLOWED, &portp->istate);
4806 portp->stats.txxoff++;
4808 if (xisr & XISR_RXXOFFGOT) {
4809 clear_bit(ASYI_TXFLOWED, &portp->istate);
4810 portp->stats.txxon++;
4814 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
4815 stl_sc26198rxbadchars(portp);
4823 * Loadable module initialization stuff.
4825 static int __init stallion_module_init(void)
4829 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
4831 spin_lock_init(&stallion_lock);
4832 spin_lock_init(&brd_lock);
4836 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
4841 * Set up a character driver for per board stuff. This is mainly used
4842 * to do stats ioctls on the ports.
4844 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
4845 printk("STALLION: failed to register serial board device\n");
4847 stallion_class = class_create(THIS_MODULE, "staliomem");
4848 for (i = 0; i < 4; i++)
4849 class_device_create(stallion_class, NULL,
4850 MKDEV(STL_SIOMEMMAJOR, i), NULL,
4853 stl_serial->owner = THIS_MODULE;
4854 stl_serial->driver_name = stl_drvname;
4855 stl_serial->name = "ttyE";
4856 stl_serial->major = STL_SERIALMAJOR;
4857 stl_serial->minor_start = 0;
4858 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
4859 stl_serial->subtype = SERIAL_TYPE_NORMAL;
4860 stl_serial->init_termios = stl_deftermios;
4861 stl_serial->flags = TTY_DRIVER_REAL_RAW;
4862 tty_set_operations(stl_serial, &stl_ops);
4864 if (tty_register_driver(stl_serial)) {
4865 put_tty_driver(stl_serial);
4866 printk("STALLION: failed to register serial driver\n");
4873 static void __exit stallion_module_exit(void)
4875 struct stlbrd *brdp;
4876 struct stlpanel *panelp;
4877 struct stlport *portp;
4880 pr_debug("cleanup_module()\n");
4882 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
4886 * Free up all allocated resources used by the ports. This includes
4887 * memory and interrupts. As part of this process we will also do
4888 * a hangup on every open port - to try to flush out any processes
4889 * hanging onto ports.
4891 i = tty_unregister_driver(stl_serial);
4892 put_tty_driver(stl_serial);
4894 printk("STALLION: failed to un-register tty driver, "
4898 for (i = 0; i < 4; i++)
4899 class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
4900 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
4901 printk("STALLION: failed to un-register serial memory device, "
4903 class_destroy(stallion_class);
4905 for (i = 0; (i < stl_nrbrds); i++) {
4906 if ((brdp = stl_brds[i]) == NULL)
4909 free_irq(brdp->irq, brdp);
4911 for (j = 0; (j < STL_MAXPANELS); j++) {
4912 panelp = brdp->panels[j];
4915 for (k = 0; (k < STL_PORTSPERPANEL); k++) {
4916 portp = panelp->ports[k];
4919 if (portp->tty != NULL)
4920 stl_hangup(portp->tty);
4921 kfree(portp->tx.buf);
4927 release_region(brdp->ioaddr1, brdp->iosize1);
4928 if (brdp->iosize2 > 0)
4929 release_region(brdp->ioaddr2, brdp->iosize2);
4936 module_init(stallion_module_init);
4937 module_exit(stallion_module_exit);
4939 MODULE_AUTHOR("Greg Ungerer");
4940 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
4941 MODULE_LICENSE("GPL");