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);
500 * CD1400 uart specific handling functions.
502 static void stl_cd1400setreg(struct stlport *portp, int regnr, int value);
503 static int stl_cd1400getreg(struct stlport *portp, int regnr);
504 static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value);
505 static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
506 static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
507 static void stl_cd1400setport(struct stlport *portp, struct termios *tiosp);
508 static int stl_cd1400getsignals(struct stlport *portp);
509 static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts);
510 static void stl_cd1400ccrwait(struct stlport *portp);
511 static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx);
512 static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx);
513 static void stl_cd1400disableintrs(struct stlport *portp);
514 static void stl_cd1400sendbreak(struct stlport *portp, int len);
515 static void stl_cd1400flowctrl(struct stlport *portp, int state);
516 static void stl_cd1400sendflow(struct stlport *portp, int state);
517 static void stl_cd1400flush(struct stlport *portp);
518 static int stl_cd1400datastate(struct stlport *portp);
519 static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase);
520 static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase);
521 static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr);
522 static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr);
523 static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr);
525 static inline int stl_cd1400breakisr(struct stlport *portp, int ioaddr);
528 * SC26198 uart specific handling functions.
530 static void stl_sc26198setreg(struct stlport *portp, int regnr, int value);
531 static int stl_sc26198getreg(struct stlport *portp, int regnr);
532 static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value);
533 static int stl_sc26198getglobreg(struct stlport *portp, int regnr);
534 static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
535 static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
536 static void stl_sc26198setport(struct stlport *portp, struct termios *tiosp);
537 static int stl_sc26198getsignals(struct stlport *portp);
538 static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts);
539 static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx);
540 static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx);
541 static void stl_sc26198disableintrs(struct stlport *portp);
542 static void stl_sc26198sendbreak(struct stlport *portp, int len);
543 static void stl_sc26198flowctrl(struct stlport *portp, int state);
544 static void stl_sc26198sendflow(struct stlport *portp, int state);
545 static void stl_sc26198flush(struct stlport *portp);
546 static int stl_sc26198datastate(struct stlport *portp);
547 static void stl_sc26198wait(struct stlport *portp);
548 static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty);
549 static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase);
550 static void stl_sc26198txisr(struct stlport *port);
551 static void stl_sc26198rxisr(struct stlport *port, unsigned int iack);
552 static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch);
553 static void stl_sc26198rxbadchars(struct stlport *portp);
554 static void stl_sc26198otherisr(struct stlport *port, unsigned int iack);
556 /*****************************************************************************/
559 * Generic UART support structure.
561 typedef struct uart {
562 int (*panelinit)(struct stlbrd *brdp, struct stlpanel *panelp);
563 void (*portinit)(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
564 void (*setport)(struct stlport *portp, struct termios *tiosp);
565 int (*getsignals)(struct stlport *portp);
566 void (*setsignals)(struct stlport *portp, int dtr, int rts);
567 void (*enablerxtx)(struct stlport *portp, int rx, int tx);
568 void (*startrxtx)(struct stlport *portp, int rx, int tx);
569 void (*disableintrs)(struct stlport *portp);
570 void (*sendbreak)(struct stlport *portp, int len);
571 void (*flowctrl)(struct stlport *portp, int state);
572 void (*sendflow)(struct stlport *portp, int state);
573 void (*flush)(struct stlport *portp);
574 int (*datastate)(struct stlport *portp);
575 void (*intr)(struct stlpanel *panelp, unsigned int iobase);
579 * Define some macros to make calling these functions nice and clean.
581 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
582 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
583 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
584 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
585 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
586 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
587 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
588 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
589 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
590 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
591 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
592 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
593 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
595 /*****************************************************************************/
598 * CD1400 UART specific data initialization.
600 static uart_t stl_cd1400uart = {
604 stl_cd1400getsignals,
605 stl_cd1400setsignals,
606 stl_cd1400enablerxtx,
608 stl_cd1400disableintrs,
618 * Define the offsets within the register bank of a cd1400 based panel.
619 * These io address offsets are common to the EasyIO board as well.
627 #define EREG_BANKSIZE 8
629 #define CD1400_CLK 25000000
630 #define CD1400_CLK8M 20000000
633 * Define the cd1400 baud rate clocks. These are used when calculating
634 * what clock and divisor to use for the required baud rate. Also
635 * define the maximum baud rate allowed, and the default base baud.
637 static int stl_cd1400clkdivs[] = {
638 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
641 /*****************************************************************************/
644 * SC26198 UART specific data initization.
646 static uart_t stl_sc26198uart = {
647 stl_sc26198panelinit,
650 stl_sc26198getsignals,
651 stl_sc26198setsignals,
652 stl_sc26198enablerxtx,
653 stl_sc26198startrxtx,
654 stl_sc26198disableintrs,
655 stl_sc26198sendbreak,
659 stl_sc26198datastate,
664 * Define the offsets within the register bank of a sc26198 based panel.
672 #define XP_BANKSIZE 4
675 * Define the sc26198 baud rate table. Offsets within the table
676 * represent the actual baud rate selector of sc26198 registers.
678 static unsigned int sc26198_baudtable[] = {
679 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
680 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
681 230400, 460800, 921600
684 #define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
686 /*****************************************************************************/
689 * Define the driver info for a user level control device. Used mainly
690 * to get at port stats - only not using the port device itself.
692 static const struct file_operations stl_fsiomem = {
693 .owner = THIS_MODULE,
694 .ioctl = stl_memioctl,
697 static struct class *stallion_class;
700 * Check for any arguments passed in on the module load command line.
703 static void stl_argbrds(void)
709 pr_debug("stl_argbrds()\n");
711 for (i = stl_nrbrds; (i < stl_nargs); i++) {
712 memset(&conf, 0, sizeof(conf));
713 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
715 if ((brdp = stl_allocbrd()) == NULL)
719 brdp->brdtype = conf.brdtype;
720 brdp->ioaddr1 = conf.ioaddr1;
721 brdp->ioaddr2 = conf.ioaddr2;
722 brdp->irq = conf.irq;
723 brdp->irqtype = conf.irqtype;
728 /*****************************************************************************/
731 * Convert an ascii string number into an unsigned long.
734 static unsigned long stl_atol(char *str)
742 if ((*sp == '0') && (*(sp+1) == 'x')) {
745 } else if (*sp == '0') {
752 for (; (*sp != 0); sp++) {
753 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
754 if ((c < 0) || (c >= base)) {
755 printk("STALLION: invalid argument %s\n", str);
759 val = (val * base) + c;
764 /*****************************************************************************/
767 * Parse the supplied argument string, into the board conf struct.
770 static int stl_parsebrd(struct stlconf *confp, char **argp)
775 pr_debug("stl_parsebrd(confp=%p,argp=%p)\n", confp, argp);
777 if ((argp[0] == NULL) || (*argp[0] == 0))
780 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
783 for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++) {
784 if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
787 if (i == ARRAY_SIZE(stl_brdstr)) {
788 printk("STALLION: unknown board name, %s?\n", argp[0]);
792 confp->brdtype = stl_brdstr[i].type;
795 if ((argp[i] != NULL) && (*argp[i] != 0))
796 confp->ioaddr1 = stl_atol(argp[i]);
798 if (confp->brdtype == BRD_ECH) {
799 if ((argp[i] != NULL) && (*argp[i] != 0))
800 confp->ioaddr2 = stl_atol(argp[i]);
803 if ((argp[i] != NULL) && (*argp[i] != 0))
804 confp->irq = stl_atol(argp[i]);
808 /*****************************************************************************/
811 * Allocate a new board structure. Fill out the basic info in it.
814 static struct stlbrd *stl_allocbrd(void)
818 brdp = kzalloc(sizeof(struct stlbrd), GFP_KERNEL);
820 printk("STALLION: failed to allocate memory (size=%Zd)\n",
821 sizeof(struct stlbrd));
825 brdp->magic = STL_BOARDMAGIC;
829 /*****************************************************************************/
831 static int stl_open(struct tty_struct *tty, struct file *filp)
833 struct stlport *portp;
835 unsigned int minordev;
836 int brdnr, panelnr, portnr, rc;
838 pr_debug("stl_open(tty=%p,filp=%p): device=%s\n", tty, filp, tty->name);
840 minordev = tty->index;
841 brdnr = MINOR2BRD(minordev);
842 if (brdnr >= stl_nrbrds)
844 brdp = stl_brds[brdnr];
847 minordev = MINOR2PORT(minordev);
848 for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
849 if (brdp->panels[panelnr] == NULL)
851 if (minordev < brdp->panels[panelnr]->nrports) {
855 minordev -= brdp->panels[panelnr]->nrports;
860 portp = brdp->panels[panelnr]->ports[portnr];
865 * On the first open of the device setup the port hardware, and
866 * initialize the per port data structure.
869 tty->driver_data = portp;
872 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
873 if (!portp->tx.buf) {
874 portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
877 portp->tx.head = portp->tx.buf;
878 portp->tx.tail = portp->tx.buf;
880 stl_setport(portp, tty->termios);
881 portp->sigs = stl_getsignals(portp);
882 stl_setsignals(portp, 1, 1);
883 stl_enablerxtx(portp, 1, 1);
884 stl_startrxtx(portp, 1, 0);
885 clear_bit(TTY_IO_ERROR, &tty->flags);
886 portp->flags |= ASYNC_INITIALIZED;
890 * Check if this port is in the middle of closing. If so then wait
891 * until it is closed then return error status, based on flag settings.
892 * The sleep here does not need interrupt protection since the wakeup
893 * for it is done with the same context.
895 if (portp->flags & ASYNC_CLOSING) {
896 interruptible_sleep_on(&portp->close_wait);
897 if (portp->flags & ASYNC_HUP_NOTIFY)
903 * Based on type of open being done check if it can overlap with any
904 * previous opens still in effect. If we are a normal serial device
905 * then also we might have to wait for carrier.
907 if (!(filp->f_flags & O_NONBLOCK)) {
908 if ((rc = stl_waitcarrier(portp, filp)) != 0)
911 portp->flags |= ASYNC_NORMAL_ACTIVE;
916 /*****************************************************************************/
919 * Possibly need to wait for carrier (DCD signal) to come high. Say
920 * maybe because if we are clocal then we don't need to wait...
923 static int stl_waitcarrier(struct stlport *portp, struct file *filp)
928 pr_debug("stl_waitcarrier(portp=%p,filp=%p)\n", portp, filp);
933 spin_lock_irqsave(&stallion_lock, flags);
935 if (portp->tty->termios->c_cflag & CLOCAL)
938 portp->openwaitcnt++;
939 if (! tty_hung_up_p(filp))
943 /* Takes brd_lock internally */
944 stl_setsignals(portp, 1, 1);
945 if (tty_hung_up_p(filp) ||
946 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
947 if (portp->flags & ASYNC_HUP_NOTIFY)
953 if (((portp->flags & ASYNC_CLOSING) == 0) &&
954 (doclocal || (portp->sigs & TIOCM_CD))) {
957 if (signal_pending(current)) {
962 interruptible_sleep_on(&portp->open_wait);
965 if (! tty_hung_up_p(filp))
967 portp->openwaitcnt--;
968 spin_unlock_irqrestore(&stallion_lock, flags);
973 /*****************************************************************************/
975 static void stl_close(struct tty_struct *tty, struct file *filp)
977 struct stlport *portp;
980 pr_debug("stl_close(tty=%p,filp=%p)\n", tty, filp);
982 portp = tty->driver_data;
986 spin_lock_irqsave(&stallion_lock, flags);
987 if (tty_hung_up_p(filp)) {
988 spin_unlock_irqrestore(&stallion_lock, flags);
991 if ((tty->count == 1) && (portp->refcount != 1))
993 if (portp->refcount-- > 1) {
994 spin_unlock_irqrestore(&stallion_lock, flags);
999 portp->flags |= ASYNC_CLOSING;
1002 * May want to wait for any data to drain before closing. The BUSY
1003 * flag keeps track of whether we are still sending or not - it is
1004 * very accurate for the cd1400, not quite so for the sc26198.
1005 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1009 spin_unlock_irqrestore(&stallion_lock, flags);
1011 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1012 tty_wait_until_sent(tty, portp->closing_wait);
1013 stl_waituntilsent(tty, (HZ / 2));
1016 spin_lock_irqsave(&stallion_lock, flags);
1017 portp->flags &= ~ASYNC_INITIALIZED;
1018 spin_unlock_irqrestore(&stallion_lock, flags);
1020 stl_disableintrs(portp);
1021 if (tty->termios->c_cflag & HUPCL)
1022 stl_setsignals(portp, 0, 0);
1023 stl_enablerxtx(portp, 0, 0);
1024 stl_flushbuffer(tty);
1026 if (portp->tx.buf != NULL) {
1027 kfree(portp->tx.buf);
1028 portp->tx.buf = NULL;
1029 portp->tx.head = NULL;
1030 portp->tx.tail = NULL;
1032 set_bit(TTY_IO_ERROR, &tty->flags);
1033 tty_ldisc_flush(tty);
1038 if (portp->openwaitcnt) {
1039 if (portp->close_delay)
1040 msleep_interruptible(jiffies_to_msecs(portp->close_delay));
1041 wake_up_interruptible(&portp->open_wait);
1044 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1045 wake_up_interruptible(&portp->close_wait);
1048 /*****************************************************************************/
1051 * Write routine. Take data and stuff it in to the TX ring queue.
1052 * If transmit interrupts are not running then start them.
1055 static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
1057 struct stlport *portp;
1058 unsigned int len, stlen;
1059 unsigned char *chbuf;
1062 pr_debug("stl_write(tty=%p,buf=%p,count=%d)\n", tty, buf, count);
1064 portp = tty->driver_data;
1067 if (portp->tx.buf == NULL)
1071 * If copying direct from user space we must cater for page faults,
1072 * causing us to "sleep" here for a while. To handle this copy in all
1073 * the data we need now, into a local buffer. Then when we got it all
1074 * copy it into the TX buffer.
1076 chbuf = (unsigned char *) buf;
1078 head = portp->tx.head;
1079 tail = portp->tx.tail;
1081 len = STL_TXBUFSIZE - (head - tail) - 1;
1082 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
1084 len = tail - head - 1;
1088 len = MIN(len, count);
1091 stlen = MIN(len, stlen);
1092 memcpy(head, chbuf, stlen);
1097 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
1098 head = portp->tx.buf;
1099 stlen = tail - head;
1102 portp->tx.head = head;
1104 clear_bit(ASYI_TXLOW, &portp->istate);
1105 stl_startrxtx(portp, -1, 1);
1110 /*****************************************************************************/
1112 static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1114 struct stlport *portp;
1118 pr_debug("stl_putchar(tty=%p,ch=%x)\n", tty, ch);
1122 portp = tty->driver_data;
1125 if (portp->tx.buf == NULL)
1128 head = portp->tx.head;
1129 tail = portp->tx.tail;
1131 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
1136 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
1137 head = portp->tx.buf;
1139 portp->tx.head = head;
1142 /*****************************************************************************/
1145 * If there are any characters in the buffer then make sure that TX
1146 * interrupts are on and get'em out. Normally used after the putchar
1147 * routine has been called.
1150 static void stl_flushchars(struct tty_struct *tty)
1152 struct stlport *portp;
1154 pr_debug("stl_flushchars(tty=%p)\n", tty);
1158 portp = tty->driver_data;
1161 if (portp->tx.buf == NULL)
1164 stl_startrxtx(portp, -1, 1);
1167 /*****************************************************************************/
1169 static int stl_writeroom(struct tty_struct *tty)
1171 struct stlport *portp;
1174 pr_debug("stl_writeroom(tty=%p)\n", tty);
1178 portp = tty->driver_data;
1181 if (portp->tx.buf == NULL)
1184 head = portp->tx.head;
1185 tail = portp->tx.tail;
1186 return ((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
1189 /*****************************************************************************/
1192 * Return number of chars in the TX buffer. Normally we would just
1193 * calculate the number of chars in the buffer and return that, but if
1194 * the buffer is empty and TX interrupts are still on then we return
1195 * that the buffer still has 1 char in it. This way whoever called us
1196 * will not think that ALL chars have drained - since the UART still
1197 * must have some chars in it (we are busy after all).
1200 static int stl_charsinbuffer(struct tty_struct *tty)
1202 struct stlport *portp;
1206 pr_debug("stl_charsinbuffer(tty=%p)\n", tty);
1210 portp = tty->driver_data;
1213 if (portp->tx.buf == NULL)
1216 head = portp->tx.head;
1217 tail = portp->tx.tail;
1218 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1219 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1224 /*****************************************************************************/
1227 * Generate the serial struct info.
1230 static int stl_getserial(struct stlport *portp, struct serial_struct __user *sp)
1232 struct serial_struct sio;
1233 struct stlbrd *brdp;
1235 pr_debug("stl_getserial(portp=%p,sp=%p)\n", portp, sp);
1237 memset(&sio, 0, sizeof(struct serial_struct));
1238 sio.line = portp->portnr;
1239 sio.port = portp->ioaddr;
1240 sio.flags = portp->flags;
1241 sio.baud_base = portp->baud_base;
1242 sio.close_delay = portp->close_delay;
1243 sio.closing_wait = portp->closing_wait;
1244 sio.custom_divisor = portp->custom_divisor;
1246 if (portp->uartp == &stl_cd1400uart) {
1247 sio.type = PORT_CIRRUS;
1248 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1250 sio.type = PORT_UNKNOWN;
1251 sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1254 brdp = stl_brds[portp->brdnr];
1256 sio.irq = brdp->irq;
1258 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
1261 /*****************************************************************************/
1264 * Set port according to the serial struct info.
1265 * At this point we do not do any auto-configure stuff, so we will
1266 * just quietly ignore any requests to change irq, etc.
1269 static int stl_setserial(struct stlport *portp, struct serial_struct __user *sp)
1271 struct serial_struct sio;
1273 pr_debug("stl_setserial(portp=%p,sp=%p)\n", portp, sp);
1275 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1277 if (!capable(CAP_SYS_ADMIN)) {
1278 if ((sio.baud_base != portp->baud_base) ||
1279 (sio.close_delay != portp->close_delay) ||
1280 ((sio.flags & ~ASYNC_USR_MASK) !=
1281 (portp->flags & ~ASYNC_USR_MASK)))
1285 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1286 (sio.flags & ASYNC_USR_MASK);
1287 portp->baud_base = sio.baud_base;
1288 portp->close_delay = sio.close_delay;
1289 portp->closing_wait = sio.closing_wait;
1290 portp->custom_divisor = sio.custom_divisor;
1291 stl_setport(portp, portp->tty->termios);
1295 /*****************************************************************************/
1297 static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1299 struct stlport *portp;
1303 portp = tty->driver_data;
1306 if (tty->flags & (1 << TTY_IO_ERROR))
1309 return stl_getsignals(portp);
1312 static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1313 unsigned int set, unsigned int clear)
1315 struct stlport *portp;
1316 int rts = -1, dtr = -1;
1320 portp = tty->driver_data;
1323 if (tty->flags & (1 << TTY_IO_ERROR))
1326 if (set & TIOCM_RTS)
1328 if (set & TIOCM_DTR)
1330 if (clear & TIOCM_RTS)
1332 if (clear & TIOCM_DTR)
1335 stl_setsignals(portp, dtr, rts);
1339 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1341 struct stlport *portp;
1344 void __user *argp = (void __user *)arg;
1346 pr_debug("stl_ioctl(tty=%p,file=%p,cmd=%x,arg=%lx)\n", tty, file, cmd,
1351 portp = tty->driver_data;
1355 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1356 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1357 if (tty->flags & (1 << TTY_IO_ERROR))
1365 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1366 (unsigned __user *) argp);
1369 if (get_user(ival, (unsigned int __user *) arg))
1371 tty->termios->c_cflag =
1372 (tty->termios->c_cflag & ~CLOCAL) |
1373 (ival ? CLOCAL : 0);
1376 rc = stl_getserial(portp, argp);
1379 rc = stl_setserial(portp, argp);
1381 case COM_GETPORTSTATS:
1382 rc = stl_getportstats(portp, argp);
1384 case COM_CLRPORTSTATS:
1385 rc = stl_clrportstats(portp, argp);
1391 case TIOCSERGSTRUCT:
1392 case TIOCSERGETMULTI:
1393 case TIOCSERSETMULTI:
1402 /*****************************************************************************/
1404 static void stl_settermios(struct tty_struct *tty, struct termios *old)
1406 struct stlport *portp;
1407 struct termios *tiosp;
1409 pr_debug("stl_settermios(tty=%p,old=%p)\n", tty, old);
1413 portp = tty->driver_data;
1417 tiosp = tty->termios;
1418 if ((tiosp->c_cflag == old->c_cflag) &&
1419 (tiosp->c_iflag == old->c_iflag))
1422 stl_setport(portp, tiosp);
1423 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1425 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1426 tty->hw_stopped = 0;
1429 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1430 wake_up_interruptible(&portp->open_wait);
1433 /*****************************************************************************/
1436 * Attempt to flow control who ever is sending us data. Based on termios
1437 * settings use software or/and hardware flow control.
1440 static void stl_throttle(struct tty_struct *tty)
1442 struct stlport *portp;
1444 pr_debug("stl_throttle(tty=%p)\n", tty);
1448 portp = tty->driver_data;
1451 stl_flowctrl(portp, 0);
1454 /*****************************************************************************/
1457 * Unflow control the device sending us data...
1460 static void stl_unthrottle(struct tty_struct *tty)
1462 struct stlport *portp;
1464 pr_debug("stl_unthrottle(tty=%p)\n", tty);
1468 portp = tty->driver_data;
1471 stl_flowctrl(portp, 1);
1474 /*****************************************************************************/
1477 * Stop the transmitter. Basically to do this we will just turn TX
1481 static void stl_stop(struct tty_struct *tty)
1483 struct stlport *portp;
1485 pr_debug("stl_stop(tty=%p)\n", tty);
1489 portp = tty->driver_data;
1492 stl_startrxtx(portp, -1, 0);
1495 /*****************************************************************************/
1498 * Start the transmitter again. Just turn TX interrupts back on.
1501 static void stl_start(struct tty_struct *tty)
1503 struct stlport *portp;
1505 pr_debug("stl_start(tty=%p)\n", tty);
1509 portp = tty->driver_data;
1512 stl_startrxtx(portp, -1, 1);
1515 /*****************************************************************************/
1518 * Hangup this port. This is pretty much like closing the port, only
1519 * a little more brutal. No waiting for data to drain. Shutdown the
1520 * port and maybe drop signals.
1523 static void stl_hangup(struct tty_struct *tty)
1525 struct stlport *portp;
1527 pr_debug("stl_hangup(tty=%p)\n", tty);
1531 portp = tty->driver_data;
1535 portp->flags &= ~ASYNC_INITIALIZED;
1536 stl_disableintrs(portp);
1537 if (tty->termios->c_cflag & HUPCL)
1538 stl_setsignals(portp, 0, 0);
1539 stl_enablerxtx(portp, 0, 0);
1540 stl_flushbuffer(tty);
1542 set_bit(TTY_IO_ERROR, &tty->flags);
1543 if (portp->tx.buf != NULL) {
1544 kfree(portp->tx.buf);
1545 portp->tx.buf = NULL;
1546 portp->tx.head = NULL;
1547 portp->tx.tail = NULL;
1550 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1551 portp->refcount = 0;
1552 wake_up_interruptible(&portp->open_wait);
1555 /*****************************************************************************/
1557 static void stl_flushbuffer(struct tty_struct *tty)
1559 struct stlport *portp;
1561 pr_debug("stl_flushbuffer(tty=%p)\n", tty);
1565 portp = tty->driver_data;
1573 /*****************************************************************************/
1575 static void stl_breakctl(struct tty_struct *tty, int state)
1577 struct stlport *portp;
1579 pr_debug("stl_breakctl(tty=%p,state=%d)\n", tty, state);
1583 portp = tty->driver_data;
1587 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1590 /*****************************************************************************/
1592 static void stl_waituntilsent(struct tty_struct *tty, int timeout)
1594 struct stlport *portp;
1597 pr_debug("stl_waituntilsent(tty=%p,timeout=%d)\n", tty, timeout);
1601 portp = tty->driver_data;
1607 tend = jiffies + timeout;
1609 while (stl_datastate(portp)) {
1610 if (signal_pending(current))
1612 msleep_interruptible(20);
1613 if (time_after_eq(jiffies, tend))
1618 /*****************************************************************************/
1620 static void stl_sendxchar(struct tty_struct *tty, char ch)
1622 struct stlport *portp;
1624 pr_debug("stl_sendxchar(tty=%p,ch=%x)\n", tty, ch);
1628 portp = tty->driver_data;
1632 if (ch == STOP_CHAR(tty))
1633 stl_sendflow(portp, 0);
1634 else if (ch == START_CHAR(tty))
1635 stl_sendflow(portp, 1);
1637 stl_putchar(tty, ch);
1640 /*****************************************************************************/
1645 * Format info for a specified port. The line is deliberately limited
1646 * to 80 characters. (If it is too long it will be truncated, if too
1647 * short then padded with spaces).
1650 static int stl_portinfo(struct stlport *portp, int portnr, char *pos)
1656 sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
1657 portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
1658 (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
1660 if (portp->stats.rxframing)
1661 sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
1662 if (portp->stats.rxparity)
1663 sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
1664 if (portp->stats.rxbreaks)
1665 sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
1666 if (portp->stats.rxoverrun)
1667 sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
1669 sigs = stl_getsignals(portp);
1670 cnt = sprintf(sp, "%s%s%s%s%s ",
1671 (sigs & TIOCM_RTS) ? "|RTS" : "",
1672 (sigs & TIOCM_CTS) ? "|CTS" : "",
1673 (sigs & TIOCM_DTR) ? "|DTR" : "",
1674 (sigs & TIOCM_CD) ? "|DCD" : "",
1675 (sigs & TIOCM_DSR) ? "|DSR" : "");
1679 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
1682 pos[(MAXLINE - 2)] = '+';
1683 pos[(MAXLINE - 1)] = '\n';
1688 /*****************************************************************************/
1691 * Port info, read from the /proc file system.
1694 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
1696 struct stlbrd *brdp;
1697 struct stlpanel *panelp;
1698 struct stlport *portp;
1699 int brdnr, panelnr, portnr, totalport;
1703 pr_debug("stl_readproc(page=%p,start=%p,off=%lx,count=%d,eof=%p,"
1704 "data=%p\n", page, start, off, count, eof, data);
1711 pos += sprintf(pos, "%s: version %s", stl_drvtitle,
1713 while (pos < (page + MAXLINE - 1))
1720 * We scan through for each board, panel and port. The offset is
1721 * calculated on the fly, and irrelevant ports are skipped.
1723 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1724 brdp = stl_brds[brdnr];
1727 if (brdp->state == 0)
1730 maxoff = curoff + (brdp->nrports * MAXLINE);
1731 if (off >= maxoff) {
1736 totalport = brdnr * STL_MAXPORTS;
1737 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1738 panelp = brdp->panels[panelnr];
1742 maxoff = curoff + (panelp->nrports * MAXLINE);
1743 if (off >= maxoff) {
1745 totalport += panelp->nrports;
1749 for (portnr = 0; (portnr < panelp->nrports); portnr++,
1751 portp = panelp->ports[portnr];
1754 if (off >= (curoff += MAXLINE))
1756 if ((pos - page + MAXLINE) > count)
1758 pos += stl_portinfo(portp, totalport, pos);
1767 return (pos - page);
1770 /*****************************************************************************/
1773 * All board interrupts are vectored through here first. This code then
1774 * calls off to the approrpriate board interrupt handlers.
1777 static irqreturn_t stl_intr(int irq, void *dev_id)
1779 struct stlbrd *brdp = dev_id;
1781 pr_debug("stl_intr(brdp=%p,irq=%d)\n", brdp, irq);
1783 return IRQ_RETVAL((* brdp->isr)(brdp));
1786 /*****************************************************************************/
1789 * Interrupt service routine for EasyIO board types.
1792 static int stl_eiointr(struct stlbrd *brdp)
1794 struct stlpanel *panelp;
1795 unsigned int iobase;
1798 spin_lock(&brd_lock);
1799 panelp = brdp->panels[0];
1800 iobase = panelp->iobase;
1801 while (inb(brdp->iostatus) & EIO_INTRPEND) {
1803 (* panelp->isr)(panelp, iobase);
1805 spin_unlock(&brd_lock);
1809 /*****************************************************************************/
1812 * Interrupt service routine for ECH-AT board types.
1815 static int stl_echatintr(struct stlbrd *brdp)
1817 struct stlpanel *panelp;
1818 unsigned int ioaddr;
1822 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
1824 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1826 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1827 ioaddr = brdp->bnkstataddr[bnknr];
1828 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1829 panelp = brdp->bnk2panel[bnknr];
1830 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1835 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
1840 /*****************************************************************************/
1843 * Interrupt service routine for ECH-MCA board types.
1846 static int stl_echmcaintr(struct stlbrd *brdp)
1848 struct stlpanel *panelp;
1849 unsigned int ioaddr;
1853 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1855 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1856 ioaddr = brdp->bnkstataddr[bnknr];
1857 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1858 panelp = brdp->bnk2panel[bnknr];
1859 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1866 /*****************************************************************************/
1869 * Interrupt service routine for ECH-PCI board types.
1872 static int stl_echpciintr(struct stlbrd *brdp)
1874 struct stlpanel *panelp;
1875 unsigned int ioaddr;
1881 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1882 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
1883 ioaddr = brdp->bnkstataddr[bnknr];
1884 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1885 panelp = brdp->bnk2panel[bnknr];
1886 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1897 /*****************************************************************************/
1900 * Interrupt service routine for ECH-8/64-PCI board types.
1903 static int stl_echpci64intr(struct stlbrd *brdp)
1905 struct stlpanel *panelp;
1906 unsigned int ioaddr;
1910 while (inb(brdp->ioctrl) & 0x1) {
1912 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1913 ioaddr = brdp->bnkstataddr[bnknr];
1914 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1915 panelp = brdp->bnk2panel[bnknr];
1916 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1924 /*****************************************************************************/
1927 * Service an off-level request for some channel.
1929 static void stl_offintr(struct work_struct *work)
1931 struct stlport *portp = container_of(work, struct stlport, tqueue);
1932 struct tty_struct *tty;
1933 unsigned int oldsigs;
1935 pr_debug("stl_offintr(portp=%p)\n", portp);
1945 if (test_bit(ASYI_TXLOW, &portp->istate)) {
1948 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
1949 clear_bit(ASYI_DCDCHANGE, &portp->istate);
1950 oldsigs = portp->sigs;
1951 portp->sigs = stl_getsignals(portp);
1952 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
1953 wake_up_interruptible(&portp->open_wait);
1954 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
1955 if (portp->flags & ASYNC_CHECK_CD)
1956 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
1962 /*****************************************************************************/
1965 * Initialize all the ports on a panel.
1968 static int __init stl_initports(struct stlbrd *brdp, struct stlpanel *panelp)
1970 struct stlport *portp;
1973 pr_debug("stl_initports(brdp=%p,panelp=%p)\n", brdp, panelp);
1975 chipmask = stl_panelinit(brdp, panelp);
1978 * All UART's are initialized (if found!). Now go through and setup
1979 * each ports data structures.
1981 for (i = 0; (i < panelp->nrports); i++) {
1982 portp = kzalloc(sizeof(struct stlport), GFP_KERNEL);
1984 printk("STALLION: failed to allocate memory "
1985 "(size=%Zd)\n", sizeof(struct stlport));
1989 portp->magic = STL_PORTMAGIC;
1991 portp->brdnr = panelp->brdnr;
1992 portp->panelnr = panelp->panelnr;
1993 portp->uartp = panelp->uartp;
1994 portp->clk = brdp->clk;
1995 portp->baud_base = STL_BAUDBASE;
1996 portp->close_delay = STL_CLOSEDELAY;
1997 portp->closing_wait = 30 * HZ;
1998 INIT_WORK(&portp->tqueue, stl_offintr);
1999 init_waitqueue_head(&portp->open_wait);
2000 init_waitqueue_head(&portp->close_wait);
2001 portp->stats.brd = portp->brdnr;
2002 portp->stats.panel = portp->panelnr;
2003 portp->stats.port = portp->portnr;
2004 panelp->ports[i] = portp;
2005 stl_portinit(brdp, panelp, portp);
2011 /*****************************************************************************/
2014 * Try to find and initialize an EasyIO board.
2017 static int stl_initeio(struct stlbrd *brdp)
2019 struct stlpanel *panelp;
2020 unsigned int status;
2024 pr_debug("stl_initeio(brdp=%p)\n", brdp);
2026 brdp->ioctrl = brdp->ioaddr1 + 1;
2027 brdp->iostatus = brdp->ioaddr1 + 2;
2029 status = inb(brdp->iostatus);
2030 if ((status & EIO_IDBITMASK) == EIO_MK3)
2034 * Handle board specific stuff now. The real difference is PCI
2037 if (brdp->brdtype == BRD_EASYIOPCI) {
2038 brdp->iosize1 = 0x80;
2039 brdp->iosize2 = 0x80;
2040 name = "serial(EIO-PCI)";
2041 outb(0x41, (brdp->ioaddr2 + 0x4c));
2044 name = "serial(EIO)";
2045 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2046 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2047 printk("STALLION: invalid irq=%d for brd=%d\n",
2048 brdp->irq, brdp->brdnr);
2051 outb((stl_vecmap[brdp->irq] | EIO_0WS |
2052 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
2056 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2057 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2058 "%x conflicts with another device\n", brdp->brdnr,
2063 if (brdp->iosize2 > 0)
2064 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2065 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2066 "address %x conflicts with another device\n",
2067 brdp->brdnr, brdp->ioaddr2);
2068 printk(KERN_WARNING "STALLION: Warning, also "
2069 "releasing board %d I/O address %x \n",
2070 brdp->brdnr, brdp->ioaddr1);
2071 release_region(brdp->ioaddr1, brdp->iosize1);
2076 * Everything looks OK, so let's go ahead and probe for the hardware.
2078 brdp->clk = CD1400_CLK;
2079 brdp->isr = stl_eiointr;
2081 switch (status & EIO_IDBITMASK) {
2083 brdp->clk = CD1400_CLK8M;
2093 switch (status & EIO_BRDMASK) {
2112 * We have verified that the board is actually present, so now we
2113 * can complete the setup.
2116 panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
2118 printk(KERN_WARNING "STALLION: failed to allocate memory "
2119 "(size=%Zd)\n", sizeof(struct stlpanel));
2123 panelp->magic = STL_PANELMAGIC;
2124 panelp->brdnr = brdp->brdnr;
2125 panelp->panelnr = 0;
2126 panelp->nrports = brdp->nrports;
2127 panelp->iobase = brdp->ioaddr1;
2128 panelp->hwid = status;
2129 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2130 panelp->uartp = &stl_sc26198uart;
2131 panelp->isr = stl_sc26198intr;
2133 panelp->uartp = &stl_cd1400uart;
2134 panelp->isr = stl_cd1400eiointr;
2137 brdp->panels[0] = panelp;
2139 brdp->state |= BRD_FOUND;
2140 brdp->hwid = status;
2141 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
2142 printk("STALLION: failed to register interrupt "
2143 "routine for %s irq=%d\n", name, brdp->irq);
2151 /*****************************************************************************/
2154 * Try to find an ECH board and initialize it. This code is capable of
2155 * dealing with all types of ECH board.
2158 static int stl_initech(struct stlbrd *brdp)
2160 struct stlpanel *panelp;
2161 unsigned int status, nxtid, ioaddr, conflict;
2162 int panelnr, banknr, i;
2165 pr_debug("stl_initech(brdp=%p)\n", brdp);
2171 * Set up the initial board register contents for boards. This varies a
2172 * bit between the different board types. So we need to handle each
2173 * separately. Also do a check that the supplied IRQ is good.
2175 switch (brdp->brdtype) {
2178 brdp->isr = stl_echatintr;
2179 brdp->ioctrl = brdp->ioaddr1 + 1;
2180 brdp->iostatus = brdp->ioaddr1 + 1;
2181 status = inb(brdp->iostatus);
2182 if ((status & ECH_IDBITMASK) != ECH_ID)
2184 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2185 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2186 printk("STALLION: invalid irq=%d for brd=%d\n",
2187 brdp->irq, brdp->brdnr);
2190 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2191 status |= (stl_vecmap[brdp->irq] << 1);
2192 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2193 brdp->ioctrlval = ECH_INTENABLE |
2194 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2195 for (i = 0; (i < 10); i++)
2196 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2199 name = "serial(EC8/32)";
2200 outb(status, brdp->ioaddr1);
2204 brdp->isr = stl_echmcaintr;
2205 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2206 brdp->iostatus = brdp->ioctrl;
2207 status = inb(brdp->iostatus);
2208 if ((status & ECH_IDBITMASK) != ECH_ID)
2210 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2211 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2212 printk("STALLION: invalid irq=%d for brd=%d\n",
2213 brdp->irq, brdp->brdnr);
2216 outb(ECHMC_BRDRESET, brdp->ioctrl);
2217 outb(ECHMC_INTENABLE, brdp->ioctrl);
2219 name = "serial(EC8/32-MC)";
2223 brdp->isr = stl_echpciintr;
2224 brdp->ioctrl = brdp->ioaddr1 + 2;
2227 name = "serial(EC8/32-PCI)";
2231 brdp->isr = stl_echpci64intr;
2232 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2233 outb(0x43, (brdp->ioaddr1 + 0x4c));
2234 brdp->iosize1 = 0x80;
2235 brdp->iosize2 = 0x80;
2236 name = "serial(EC8/64-PCI)";
2240 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
2246 * Check boards for possible IO address conflicts and return fail status
2247 * if an IO conflict found.
2249 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2250 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2251 "%x conflicts with another device\n", brdp->brdnr,
2256 if (brdp->iosize2 > 0)
2257 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2258 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2259 "address %x conflicts with another device\n",
2260 brdp->brdnr, brdp->ioaddr2);
2261 printk(KERN_WARNING "STALLION: Warning, also "
2262 "releasing board %d I/O address %x \n",
2263 brdp->brdnr, brdp->ioaddr1);
2264 release_region(brdp->ioaddr1, brdp->iosize1);
2269 * Scan through the secondary io address space looking for panels.
2270 * As we find'em allocate and initialize panel structures for each.
2272 brdp->clk = CD1400_CLK;
2273 brdp->hwid = status;
2275 ioaddr = brdp->ioaddr2;
2280 for (i = 0; (i < STL_MAXPANELS); i++) {
2281 if (brdp->brdtype == BRD_ECHPCI) {
2282 outb(nxtid, brdp->ioctrl);
2283 ioaddr = brdp->ioaddr2;
2285 status = inb(ioaddr + ECH_PNLSTATUS);
2286 if ((status & ECH_PNLIDMASK) != nxtid)
2288 panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
2290 printk("STALLION: failed to allocate memory "
2291 "(size=%Zd)\n", sizeof(struct stlpanel));
2294 panelp->magic = STL_PANELMAGIC;
2295 panelp->brdnr = brdp->brdnr;
2296 panelp->panelnr = panelnr;
2297 panelp->iobase = ioaddr;
2298 panelp->pagenr = nxtid;
2299 panelp->hwid = status;
2300 brdp->bnk2panel[banknr] = panelp;
2301 brdp->bnkpageaddr[banknr] = nxtid;
2302 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2304 if (status & ECH_PNLXPID) {
2305 panelp->uartp = &stl_sc26198uart;
2306 panelp->isr = stl_sc26198intr;
2307 if (status & ECH_PNL16PORT) {
2308 panelp->nrports = 16;
2309 brdp->bnk2panel[banknr] = panelp;
2310 brdp->bnkpageaddr[banknr] = nxtid;
2311 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2314 panelp->nrports = 8;
2317 panelp->uartp = &stl_cd1400uart;
2318 panelp->isr = stl_cd1400echintr;
2319 if (status & ECH_PNL16PORT) {
2320 panelp->nrports = 16;
2321 panelp->ackmask = 0x80;
2322 if (brdp->brdtype != BRD_ECHPCI)
2323 ioaddr += EREG_BANKSIZE;
2324 brdp->bnk2panel[banknr] = panelp;
2325 brdp->bnkpageaddr[banknr] = ++nxtid;
2326 brdp->bnkstataddr[banknr++] = ioaddr +
2329 panelp->nrports = 8;
2330 panelp->ackmask = 0xc0;
2335 ioaddr += EREG_BANKSIZE;
2336 brdp->nrports += panelp->nrports;
2337 brdp->panels[panelnr++] = panelp;
2338 if ((brdp->brdtype != BRD_ECHPCI) &&
2339 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
2343 brdp->nrpanels = panelnr;
2344 brdp->nrbnks = banknr;
2345 if (brdp->brdtype == BRD_ECH)
2346 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2348 brdp->state |= BRD_FOUND;
2349 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
2350 printk("STALLION: failed to register interrupt "
2351 "routine for %s irq=%d\n", name, brdp->irq);
2360 /*****************************************************************************/
2363 * Initialize and configure the specified board.
2364 * Scan through all the boards in the configuration and see what we
2365 * can find. Handle EIO and the ECH boards a little differently here
2366 * since the initial search and setup is very different.
2369 static int __init stl_brdinit(struct stlbrd *brdp)
2373 pr_debug("stl_brdinit(brdp=%p)\n", brdp);
2375 switch (brdp->brdtype) {
2387 printk("STALLION: board=%d is unknown board type=%d\n",
2388 brdp->brdnr, brdp->brdtype);
2392 stl_brds[brdp->brdnr] = brdp;
2393 if ((brdp->state & BRD_FOUND) == 0) {
2394 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2395 stl_brdnames[brdp->brdtype], brdp->brdnr,
2396 brdp->ioaddr1, brdp->irq);
2400 for (i = 0; (i < STL_MAXPANELS); i++)
2401 if (brdp->panels[i] != NULL)
2402 stl_initports(brdp, brdp->panels[i]);
2404 printk("STALLION: %s found, board=%d io=%x irq=%d "
2405 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2406 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2411 /*****************************************************************************/
2414 * Find the next available board number that is free.
2417 static int stl_getbrdnr(void)
2421 for (i = 0; (i < STL_MAXBRDS); i++) {
2422 if (stl_brds[i] == NULL) {
2423 if (i >= stl_nrbrds)
2431 /*****************************************************************************/
2436 * We have a Stallion board. Allocate a board structure and
2437 * initialize it. Read its IO and IRQ resources from PCI
2438 * configuration space.
2441 static int stl_initpcibrd(int brdtype, struct pci_dev *devp)
2443 struct stlbrd *brdp;
2445 pr_debug("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
2446 devp->bus->number, devp->devfn);
2448 if (pci_enable_device(devp))
2450 if ((brdp = stl_allocbrd()) == NULL)
2452 if ((brdp->brdnr = stl_getbrdnr()) < 0) {
2453 printk("STALLION: too many boards found, "
2454 "maximum supported %d\n", STL_MAXBRDS);
2457 brdp->brdtype = brdtype;
2460 * Different Stallion boards use the BAR registers in different ways,
2461 * so set up io addresses based on board type.
2463 pr_debug("%s(%d): BAR[]=%Lx,%Lx,%Lx,%Lx IRQ=%x\n", __FILE__, __LINE__,
2464 pci_resource_start(devp, 0), pci_resource_start(devp, 1),
2465 pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
2468 * We have all resources from the board, so let's setup the actual
2469 * board structure now.
2473 brdp->ioaddr2 = pci_resource_start(devp, 0);
2474 brdp->ioaddr1 = pci_resource_start(devp, 1);
2477 brdp->ioaddr2 = pci_resource_start(devp, 2);
2478 brdp->ioaddr1 = pci_resource_start(devp, 1);
2481 brdp->ioaddr1 = pci_resource_start(devp, 2);
2482 brdp->ioaddr2 = pci_resource_start(devp, 1);
2485 printk("STALLION: unknown PCI board type=%d\n", brdtype);
2489 brdp->irq = devp->irq;
2495 /*****************************************************************************/
2498 * Find all Stallion PCI boards that might be installed. Initialize each
2499 * one as it is found.
2503 static int stl_findpcibrds(void)
2505 struct pci_dev *dev = NULL;
2508 pr_debug("stl_findpcibrds()\n");
2510 for (i = 0; (i < stl_nrpcibrds); i++)
2511 while ((dev = pci_find_device(stl_pcibrds[i].vendid,
2512 stl_pcibrds[i].devid, dev))) {
2515 * Found a device on the PCI bus that has our vendor and
2516 * device ID. Need to check now that it is really us.
2518 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2521 rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
2531 /*****************************************************************************/
2534 * Scan through all the boards in the configuration and see what we
2535 * can find. Handle EIO and the ECH boards a little differently here
2536 * since the initial search and setup is too different.
2539 static int stl_initbrds(void)
2541 struct stlbrd *brdp;
2542 struct stlconf *confp;
2545 pr_debug("stl_initbrds()\n");
2547 if (stl_nrbrds > STL_MAXBRDS) {
2548 printk("STALLION: too many boards in configuration table, "
2549 "truncating to %d\n", STL_MAXBRDS);
2550 stl_nrbrds = STL_MAXBRDS;
2554 * Firstly scan the list of static boards configured. Allocate
2555 * resources and initialize the boards as found.
2557 for (i = 0; (i < stl_nrbrds); i++) {
2558 confp = &stl_brdconf[i];
2559 stl_parsebrd(confp, stl_brdsp[i]);
2560 if ((brdp = stl_allocbrd()) == NULL)
2563 brdp->brdtype = confp->brdtype;
2564 brdp->ioaddr1 = confp->ioaddr1;
2565 brdp->ioaddr2 = confp->ioaddr2;
2566 brdp->irq = confp->irq;
2567 brdp->irqtype = confp->irqtype;
2572 * Find any dynamically supported boards. That is via module load
2573 * line options or auto-detected on the PCI bus.
2583 /*****************************************************************************/
2586 * Return the board stats structure to user app.
2589 static int stl_getbrdstats(combrd_t __user *bp)
2591 struct stlbrd *brdp;
2592 struct stlpanel *panelp;
2595 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2597 if (stl_brdstats.brd >= STL_MAXBRDS)
2599 brdp = stl_brds[stl_brdstats.brd];
2603 memset(&stl_brdstats, 0, sizeof(combrd_t));
2604 stl_brdstats.brd = brdp->brdnr;
2605 stl_brdstats.type = brdp->brdtype;
2606 stl_brdstats.hwid = brdp->hwid;
2607 stl_brdstats.state = brdp->state;
2608 stl_brdstats.ioaddr = brdp->ioaddr1;
2609 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2610 stl_brdstats.irq = brdp->irq;
2611 stl_brdstats.nrpanels = brdp->nrpanels;
2612 stl_brdstats.nrports = brdp->nrports;
2613 for (i = 0; (i < brdp->nrpanels); i++) {
2614 panelp = brdp->panels[i];
2615 stl_brdstats.panels[i].panel = i;
2616 stl_brdstats.panels[i].hwid = panelp->hwid;
2617 stl_brdstats.panels[i].nrports = panelp->nrports;
2620 return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
2623 /*****************************************************************************/
2626 * Resolve the referenced port number into a port struct pointer.
2629 static struct stlport *stl_getport(int brdnr, int panelnr, int portnr)
2631 struct stlbrd *brdp;
2632 struct stlpanel *panelp;
2634 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2636 brdp = stl_brds[brdnr];
2639 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2641 panelp = brdp->panels[panelnr];
2644 if ((portnr < 0) || (portnr >= panelp->nrports))
2646 return(panelp->ports[portnr]);
2649 /*****************************************************************************/
2652 * Return the port stats structure to user app. A NULL port struct
2653 * pointer passed in means that we need to find out from the app
2654 * what port to get stats for (used through board control device).
2657 static int stl_getportstats(struct stlport *portp, comstats_t __user *cp)
2659 unsigned char *head, *tail;
2660 unsigned long flags;
2663 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2665 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2671 portp->stats.state = portp->istate;
2672 portp->stats.flags = portp->flags;
2673 portp->stats.hwid = portp->hwid;
2675 portp->stats.ttystate = 0;
2676 portp->stats.cflags = 0;
2677 portp->stats.iflags = 0;
2678 portp->stats.oflags = 0;
2679 portp->stats.lflags = 0;
2680 portp->stats.rxbuffered = 0;
2682 spin_lock_irqsave(&stallion_lock, flags);
2683 if (portp->tty != NULL) {
2684 if (portp->tty->driver_data == portp) {
2685 portp->stats.ttystate = portp->tty->flags;
2686 /* No longer available as a statistic */
2687 portp->stats.rxbuffered = 1; /*portp->tty->flip.count; */
2688 if (portp->tty->termios != NULL) {
2689 portp->stats.cflags = portp->tty->termios->c_cflag;
2690 portp->stats.iflags = portp->tty->termios->c_iflag;
2691 portp->stats.oflags = portp->tty->termios->c_oflag;
2692 portp->stats.lflags = portp->tty->termios->c_lflag;
2696 spin_unlock_irqrestore(&stallion_lock, flags);
2698 head = portp->tx.head;
2699 tail = portp->tx.tail;
2700 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2701 (STL_TXBUFSIZE - (tail - head)));
2703 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2705 return copy_to_user(cp, &portp->stats,
2706 sizeof(comstats_t)) ? -EFAULT : 0;
2709 /*****************************************************************************/
2712 * Clear the port stats structure. We also return it zeroed out...
2715 static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp)
2718 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2720 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2726 memset(&portp->stats, 0, sizeof(comstats_t));
2727 portp->stats.brd = portp->brdnr;
2728 portp->stats.panel = portp->panelnr;
2729 portp->stats.port = portp->portnr;
2730 return copy_to_user(cp, &portp->stats,
2731 sizeof(comstats_t)) ? -EFAULT : 0;
2734 /*****************************************************************************/
2737 * Return the entire driver ports structure to a user app.
2740 static int stl_getportstruct(struct stlport __user *arg)
2742 struct stlport *portp;
2744 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
2746 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
2747 stl_dummyport.portnr);
2750 return copy_to_user(arg, portp, sizeof(struct stlport)) ? -EFAULT : 0;
2753 /*****************************************************************************/
2756 * Return the entire driver board structure to a user app.
2759 static int stl_getbrdstruct(struct stlbrd __user *arg)
2761 struct stlbrd *brdp;
2763 if (copy_from_user(&stl_dummybrd, arg, sizeof(struct stlbrd)))
2765 if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
2767 brdp = stl_brds[stl_dummybrd.brdnr];
2770 return copy_to_user(arg, brdp, sizeof(struct stlbrd)) ? -EFAULT : 0;
2773 /*****************************************************************************/
2776 * The "staliomem" device is also required to do some special operations
2777 * on the board and/or ports. In this driver it is mostly used for stats
2781 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
2784 void __user *argp = (void __user *)arg;
2786 pr_debug("stl_memioctl(ip=%p,fp=%p,cmd=%x,arg=%lx)\n", ip, fp, cmd,arg);
2789 if (brdnr >= STL_MAXBRDS)
2794 case COM_GETPORTSTATS:
2795 rc = stl_getportstats(NULL, argp);
2797 case COM_CLRPORTSTATS:
2798 rc = stl_clrportstats(NULL, argp);
2800 case COM_GETBRDSTATS:
2801 rc = stl_getbrdstats(argp);
2804 rc = stl_getportstruct(argp);
2807 rc = stl_getbrdstruct(argp);
2817 static const struct tty_operations stl_ops = {
2821 .put_char = stl_putchar,
2822 .flush_chars = stl_flushchars,
2823 .write_room = stl_writeroom,
2824 .chars_in_buffer = stl_charsinbuffer,
2826 .set_termios = stl_settermios,
2827 .throttle = stl_throttle,
2828 .unthrottle = stl_unthrottle,
2831 .hangup = stl_hangup,
2832 .flush_buffer = stl_flushbuffer,
2833 .break_ctl = stl_breakctl,
2834 .wait_until_sent = stl_waituntilsent,
2835 .send_xchar = stl_sendxchar,
2836 .read_proc = stl_readproc,
2837 .tiocmget = stl_tiocmget,
2838 .tiocmset = stl_tiocmset,
2841 /*****************************************************************************/
2842 /* CD1400 HARDWARE FUNCTIONS */
2843 /*****************************************************************************/
2846 * These functions get/set/update the registers of the cd1400 UARTs.
2847 * Access to the cd1400 registers is via an address/data io port pair.
2848 * (Maybe should make this inline...)
2851 static int stl_cd1400getreg(struct stlport *portp, int regnr)
2853 outb((regnr + portp->uartaddr), portp->ioaddr);
2854 return inb(portp->ioaddr + EREG_DATA);
2857 static void stl_cd1400setreg(struct stlport *portp, int regnr, int value)
2859 outb((regnr + portp->uartaddr), portp->ioaddr);
2860 outb(value, portp->ioaddr + EREG_DATA);
2863 static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value)
2865 outb((regnr + portp->uartaddr), portp->ioaddr);
2866 if (inb(portp->ioaddr + EREG_DATA) != value) {
2867 outb(value, portp->ioaddr + EREG_DATA);
2873 /*****************************************************************************/
2876 * Inbitialize the UARTs in a panel. We don't care what sort of board
2877 * these ports are on - since the port io registers are almost
2878 * identical when dealing with ports.
2881 static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
2885 int nrchips, uartaddr, ioaddr;
2886 unsigned long flags;
2888 pr_debug("stl_panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
2890 spin_lock_irqsave(&brd_lock, flags);
2891 BRDENABLE(panelp->brdnr, panelp->pagenr);
2894 * Check that each chip is present and started up OK.
2897 nrchips = panelp->nrports / CD1400_PORTS;
2898 for (i = 0; (i < nrchips); i++) {
2899 if (brdp->brdtype == BRD_ECHPCI) {
2900 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
2901 ioaddr = panelp->iobase;
2903 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
2905 uartaddr = (i & 0x01) ? 0x080 : 0;
2906 outb((GFRCR + uartaddr), ioaddr);
2907 outb(0, (ioaddr + EREG_DATA));
2908 outb((CCR + uartaddr), ioaddr);
2909 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
2910 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
2911 outb((GFRCR + uartaddr), ioaddr);
2912 for (j = 0; (j < CCR_MAXWAIT); j++) {
2913 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
2916 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
2917 printk("STALLION: cd1400 not responding, "
2918 "brd=%d panel=%d chip=%d\n",
2919 panelp->brdnr, panelp->panelnr, i);
2922 chipmask |= (0x1 << i);
2923 outb((PPR + uartaddr), ioaddr);
2924 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
2927 BRDDISABLE(panelp->brdnr);
2928 spin_unlock_irqrestore(&brd_lock, flags);
2932 /*****************************************************************************/
2935 * Initialize hardware specific port registers.
2938 static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
2940 unsigned long flags;
2941 pr_debug("stl_cd1400portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
2944 if ((brdp == NULL) || (panelp == NULL) ||
2948 spin_lock_irqsave(&brd_lock, flags);
2949 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
2950 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
2951 portp->uartaddr = (portp->portnr & 0x04) << 5;
2952 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
2954 BRDENABLE(portp->brdnr, portp->pagenr);
2955 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2956 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
2957 portp->hwid = stl_cd1400getreg(portp, GFRCR);
2958 BRDDISABLE(portp->brdnr);
2959 spin_unlock_irqrestore(&brd_lock, flags);
2962 /*****************************************************************************/
2965 * Wait for the command register to be ready. We will poll this,
2966 * since it won't usually take too long to be ready.
2969 static void stl_cd1400ccrwait(struct stlport *portp)
2973 for (i = 0; (i < CCR_MAXWAIT); i++) {
2974 if (stl_cd1400getreg(portp, CCR) == 0) {
2979 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
2980 portp->portnr, portp->panelnr, portp->brdnr);
2983 /*****************************************************************************/
2986 * Set up the cd1400 registers for a port based on the termios port
2990 static void stl_cd1400setport(struct stlport *portp, struct termios *tiosp)
2992 struct stlbrd *brdp;
2993 unsigned long flags;
2994 unsigned int clkdiv, baudrate;
2995 unsigned char cor1, cor2, cor3;
2996 unsigned char cor4, cor5, ccr;
2997 unsigned char srer, sreron, sreroff;
2998 unsigned char mcor1, mcor2, rtpr;
2999 unsigned char clk, div;
3015 brdp = stl_brds[portp->brdnr];
3020 * Set up the RX char ignore mask with those RX error types we
3021 * can ignore. We can get the cd1400 to help us out a little here,
3022 * it will ignore parity errors and breaks for us.
3024 portp->rxignoremsk = 0;
3025 if (tiosp->c_iflag & IGNPAR) {
3026 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
3027 cor1 |= COR1_PARIGNORE;
3029 if (tiosp->c_iflag & IGNBRK) {
3030 portp->rxignoremsk |= ST_BREAK;
3031 cor4 |= COR4_IGNBRK;
3034 portp->rxmarkmsk = ST_OVERRUN;
3035 if (tiosp->c_iflag & (INPCK | PARMRK))
3036 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3037 if (tiosp->c_iflag & BRKINT)
3038 portp->rxmarkmsk |= ST_BREAK;
3041 * Go through the char size, parity and stop bits and set all the
3042 * option register appropriately.
3044 switch (tiosp->c_cflag & CSIZE) {
3059 if (tiosp->c_cflag & CSTOPB)
3064 if (tiosp->c_cflag & PARENB) {
3065 if (tiosp->c_cflag & PARODD)
3066 cor1 |= (COR1_PARENB | COR1_PARODD);
3068 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3070 cor1 |= COR1_PARNONE;
3074 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3075 * space for hardware flow control and the like. This should be set to
3076 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3077 * really be based on VTIME.
3079 cor3 |= FIFO_RXTHRESHOLD;
3083 * Calculate the baud rate timers. For now we will just assume that
3084 * the input and output baud are the same. Could have used a baud
3085 * table here, but this way we can generate virtually any baud rate
3088 baudrate = tiosp->c_cflag & CBAUD;
3089 if (baudrate & CBAUDEX) {
3090 baudrate &= ~CBAUDEX;
3091 if ((baudrate < 1) || (baudrate > 4))
3092 tiosp->c_cflag &= ~CBAUDEX;
3096 baudrate = stl_baudrates[baudrate];
3097 if ((tiosp->c_cflag & CBAUD) == B38400) {
3098 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3100 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3102 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3104 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3106 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3107 baudrate = (portp->baud_base / portp->custom_divisor);
3109 if (baudrate > STL_CD1400MAXBAUD)
3110 baudrate = STL_CD1400MAXBAUD;
3113 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3114 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
3118 div = (unsigned char) clkdiv;
3122 * Check what form of modem signaling is required and set it up.
3124 if ((tiosp->c_cflag & CLOCAL) == 0) {
3127 sreron |= SRER_MODEM;
3128 portp->flags |= ASYNC_CHECK_CD;
3130 portp->flags &= ~ASYNC_CHECK_CD;
3134 * Setup cd1400 enhanced modes if we can. In particular we want to
3135 * handle as much of the flow control as possible automatically. As
3136 * well as saving a few CPU cycles it will also greatly improve flow
3137 * control reliability.
3139 if (tiosp->c_iflag & IXON) {
3142 if (tiosp->c_iflag & IXANY)
3146 if (tiosp->c_cflag & CRTSCTS) {
3148 mcor1 |= FIFO_RTSTHRESHOLD;
3152 * All cd1400 register values calculated so go through and set
3156 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3157 portp->portnr, portp->panelnr, portp->brdnr);
3158 pr_debug(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3159 cor1, cor2, cor3, cor4, cor5);
3160 pr_debug(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3161 mcor1, mcor2, rtpr, sreron, sreroff);
3162 pr_debug(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3163 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3164 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3165 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3167 spin_lock_irqsave(&brd_lock, flags);
3168 BRDENABLE(portp->brdnr, portp->pagenr);
3169 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3170 srer = stl_cd1400getreg(portp, SRER);
3171 stl_cd1400setreg(portp, SRER, 0);
3172 if (stl_cd1400updatereg(portp, COR1, cor1))
3174 if (stl_cd1400updatereg(portp, COR2, cor2))
3176 if (stl_cd1400updatereg(portp, COR3, cor3))
3179 stl_cd1400ccrwait(portp);
3180 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3182 stl_cd1400setreg(portp, COR4, cor4);
3183 stl_cd1400setreg(portp, COR5, cor5);
3184 stl_cd1400setreg(portp, MCOR1, mcor1);
3185 stl_cd1400setreg(portp, MCOR2, mcor2);
3187 stl_cd1400setreg(portp, TCOR, clk);
3188 stl_cd1400setreg(portp, TBPR, div);
3189 stl_cd1400setreg(portp, RCOR, clk);
3190 stl_cd1400setreg(portp, RBPR, div);
3192 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3193 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3194 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3195 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3196 stl_cd1400setreg(portp, RTPR, rtpr);
3197 mcor1 = stl_cd1400getreg(portp, MSVR1);
3198 if (mcor1 & MSVR1_DCD)
3199 portp->sigs |= TIOCM_CD;
3201 portp->sigs &= ~TIOCM_CD;
3202 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3203 BRDDISABLE(portp->brdnr);
3204 spin_unlock_irqrestore(&brd_lock, flags);
3207 /*****************************************************************************/
3210 * Set the state of the DTR and RTS signals.
3213 static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts)
3215 unsigned char msvr1, msvr2;
3216 unsigned long flags;
3218 pr_debug("stl_cd1400setsignals(portp=%p,dtr=%d,rts=%d)\n",
3228 spin_lock_irqsave(&brd_lock, flags);
3229 BRDENABLE(portp->brdnr, portp->pagenr);
3230 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3232 stl_cd1400setreg(portp, MSVR2, msvr2);
3234 stl_cd1400setreg(portp, MSVR1, msvr1);
3235 BRDDISABLE(portp->brdnr);
3236 spin_unlock_irqrestore(&brd_lock, flags);
3239 /*****************************************************************************/
3242 * Return the state of the signals.
3245 static int stl_cd1400getsignals(struct stlport *portp)
3247 unsigned char msvr1, msvr2;
3248 unsigned long flags;
3251 pr_debug("stl_cd1400getsignals(portp=%p)\n", portp);
3253 spin_lock_irqsave(&brd_lock, flags);
3254 BRDENABLE(portp->brdnr, portp->pagenr);
3255 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3256 msvr1 = stl_cd1400getreg(portp, MSVR1);
3257 msvr2 = stl_cd1400getreg(portp, MSVR2);
3258 BRDDISABLE(portp->brdnr);
3259 spin_unlock_irqrestore(&brd_lock, flags);
3262 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3263 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3264 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3265 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3267 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3268 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3275 /*****************************************************************************/
3278 * Enable/Disable the Transmitter and/or Receiver.
3281 static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx)
3284 unsigned long flags;
3286 pr_debug("stl_cd1400enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
3291 ccr |= CCR_TXDISABLE;
3293 ccr |= CCR_TXENABLE;
3295 ccr |= CCR_RXDISABLE;
3297 ccr |= CCR_RXENABLE;
3299 spin_lock_irqsave(&brd_lock, flags);
3300 BRDENABLE(portp->brdnr, portp->pagenr);
3301 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3302 stl_cd1400ccrwait(portp);
3303 stl_cd1400setreg(portp, CCR, ccr);
3304 stl_cd1400ccrwait(portp);
3305 BRDDISABLE(portp->brdnr);
3306 spin_unlock_irqrestore(&brd_lock, flags);
3309 /*****************************************************************************/
3312 * Start/stop the Transmitter and/or Receiver.
3315 static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx)
3317 unsigned char sreron, sreroff;
3318 unsigned long flags;
3320 pr_debug("stl_cd1400startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
3325 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3327 sreron |= SRER_TXDATA;
3329 sreron |= SRER_TXEMPTY;
3331 sreroff |= SRER_RXDATA;
3333 sreron |= SRER_RXDATA;
3335 spin_lock_irqsave(&brd_lock, flags);
3336 BRDENABLE(portp->brdnr, portp->pagenr);
3337 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3338 stl_cd1400setreg(portp, SRER,
3339 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3340 BRDDISABLE(portp->brdnr);
3342 set_bit(ASYI_TXBUSY, &portp->istate);
3343 spin_unlock_irqrestore(&brd_lock, flags);
3346 /*****************************************************************************/
3349 * Disable all interrupts from this port.
3352 static void stl_cd1400disableintrs(struct stlport *portp)
3354 unsigned long flags;
3356 pr_debug("stl_cd1400disableintrs(portp=%p)\n", portp);
3358 spin_lock_irqsave(&brd_lock, flags);
3359 BRDENABLE(portp->brdnr, portp->pagenr);
3360 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3361 stl_cd1400setreg(portp, SRER, 0);
3362 BRDDISABLE(portp->brdnr);
3363 spin_unlock_irqrestore(&brd_lock, flags);
3366 /*****************************************************************************/
3368 static void stl_cd1400sendbreak(struct stlport *portp, int len)
3370 unsigned long flags;
3372 pr_debug("stl_cd1400sendbreak(portp=%p,len=%d)\n", portp, len);
3374 spin_lock_irqsave(&brd_lock, flags);
3375 BRDENABLE(portp->brdnr, portp->pagenr);
3376 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3377 stl_cd1400setreg(portp, SRER,
3378 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3380 BRDDISABLE(portp->brdnr);
3381 portp->brklen = len;
3383 portp->stats.txbreaks++;
3384 spin_unlock_irqrestore(&brd_lock, flags);
3387 /*****************************************************************************/
3390 * Take flow control actions...
3393 static void stl_cd1400flowctrl(struct stlport *portp, int state)
3395 struct tty_struct *tty;
3396 unsigned long flags;
3398 pr_debug("stl_cd1400flowctrl(portp=%p,state=%x)\n", portp, state);
3406 spin_lock_irqsave(&brd_lock, flags);
3407 BRDENABLE(portp->brdnr, portp->pagenr);
3408 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3411 if (tty->termios->c_iflag & IXOFF) {
3412 stl_cd1400ccrwait(portp);
3413 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3414 portp->stats.rxxon++;
3415 stl_cd1400ccrwait(portp);
3418 * Question: should we return RTS to what it was before? It may
3419 * have been set by an ioctl... Suppose not, since if you have
3420 * hardware flow control set then it is pretty silly to go and
3421 * set the RTS line by hand.
3423 if (tty->termios->c_cflag & CRTSCTS) {
3424 stl_cd1400setreg(portp, MCOR1,
3425 (stl_cd1400getreg(portp, MCOR1) |
3426 FIFO_RTSTHRESHOLD));
3427 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3428 portp->stats.rxrtson++;
3431 if (tty->termios->c_iflag & IXOFF) {
3432 stl_cd1400ccrwait(portp);
3433 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3434 portp->stats.rxxoff++;
3435 stl_cd1400ccrwait(portp);
3437 if (tty->termios->c_cflag & CRTSCTS) {
3438 stl_cd1400setreg(portp, MCOR1,
3439 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3440 stl_cd1400setreg(portp, MSVR2, 0);
3441 portp->stats.rxrtsoff++;
3445 BRDDISABLE(portp->brdnr);
3446 spin_unlock_irqrestore(&brd_lock, flags);
3449 /*****************************************************************************/
3452 * Send a flow control character...
3455 static void stl_cd1400sendflow(struct stlport *portp, int state)
3457 struct tty_struct *tty;
3458 unsigned long flags;
3460 pr_debug("stl_cd1400sendflow(portp=%p,state=%x)\n", portp, state);
3468 spin_lock_irqsave(&brd_lock, flags);
3469 BRDENABLE(portp->brdnr, portp->pagenr);
3470 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3472 stl_cd1400ccrwait(portp);
3473 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3474 portp->stats.rxxon++;
3475 stl_cd1400ccrwait(portp);
3477 stl_cd1400ccrwait(portp);
3478 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3479 portp->stats.rxxoff++;
3480 stl_cd1400ccrwait(portp);
3482 BRDDISABLE(portp->brdnr);
3483 spin_unlock_irqrestore(&brd_lock, flags);
3486 /*****************************************************************************/
3488 static void stl_cd1400flush(struct stlport *portp)
3490 unsigned long flags;
3492 pr_debug("stl_cd1400flush(portp=%p)\n", portp);
3497 spin_lock_irqsave(&brd_lock, flags);
3498 BRDENABLE(portp->brdnr, portp->pagenr);
3499 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3500 stl_cd1400ccrwait(portp);
3501 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3502 stl_cd1400ccrwait(portp);
3503 portp->tx.tail = portp->tx.head;
3504 BRDDISABLE(portp->brdnr);
3505 spin_unlock_irqrestore(&brd_lock, flags);
3508 /*****************************************************************************/
3511 * Return the current state of data flow on this port. This is only
3512 * really interresting when determining if data has fully completed
3513 * transmission or not... This is easy for the cd1400, it accurately
3514 * maintains the busy port flag.
3517 static int stl_cd1400datastate(struct stlport *portp)
3519 pr_debug("stl_cd1400datastate(portp=%p)\n", portp);
3524 return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
3527 /*****************************************************************************/
3530 * Interrupt service routine for cd1400 EasyIO boards.
3533 static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase)
3535 unsigned char svrtype;
3537 pr_debug("stl_cd1400eiointr(panelp=%p,iobase=%x)\n", panelp, iobase);
3539 spin_lock(&brd_lock);
3541 svrtype = inb(iobase + EREG_DATA);
3542 if (panelp->nrports > 4) {
3543 outb((SVRR + 0x80), iobase);
3544 svrtype |= inb(iobase + EREG_DATA);
3547 if (svrtype & SVRR_RX)
3548 stl_cd1400rxisr(panelp, iobase);
3549 else if (svrtype & SVRR_TX)
3550 stl_cd1400txisr(panelp, iobase);
3551 else if (svrtype & SVRR_MDM)
3552 stl_cd1400mdmisr(panelp, iobase);
3554 spin_unlock(&brd_lock);
3557 /*****************************************************************************/
3560 * Interrupt service routine for cd1400 panels.
3563 static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase)
3565 unsigned char svrtype;
3567 pr_debug("stl_cd1400echintr(panelp=%p,iobase=%x)\n", panelp, iobase);
3570 svrtype = inb(iobase + EREG_DATA);
3571 outb((SVRR + 0x80), iobase);
3572 svrtype |= inb(iobase + EREG_DATA);
3573 if (svrtype & SVRR_RX)
3574 stl_cd1400rxisr(panelp, iobase);
3575 else if (svrtype & SVRR_TX)
3576 stl_cd1400txisr(panelp, iobase);
3577 else if (svrtype & SVRR_MDM)
3578 stl_cd1400mdmisr(panelp, iobase);
3582 /*****************************************************************************/
3585 * Unfortunately we need to handle breaks in the TX data stream, since
3586 * this is the only way to generate them on the cd1400.
3589 static int stl_cd1400breakisr(struct stlport *portp, int ioaddr)
3591 if (portp->brklen == 1) {
3592 outb((COR2 + portp->uartaddr), ioaddr);
3593 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
3594 (ioaddr + EREG_DATA));
3595 outb((TDR + portp->uartaddr), ioaddr);
3596 outb(ETC_CMD, (ioaddr + EREG_DATA));
3597 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
3598 outb((SRER + portp->uartaddr), ioaddr);
3599 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
3600 (ioaddr + EREG_DATA));
3602 } else if (portp->brklen > 1) {
3603 outb((TDR + portp->uartaddr), ioaddr);
3604 outb(ETC_CMD, (ioaddr + EREG_DATA));
3605 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
3609 outb((COR2 + portp->uartaddr), ioaddr);
3610 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
3611 (ioaddr + EREG_DATA));
3617 /*****************************************************************************/
3620 * Transmit interrupt handler. This has gotta be fast! Handling TX
3621 * chars is pretty simple, stuff as many as possible from the TX buffer
3622 * into the cd1400 FIFO. Must also handle TX breaks here, since they
3623 * are embedded as commands in the data stream. Oh no, had to use a goto!
3624 * This could be optimized more, will do when I get time...
3625 * In practice it is possible that interrupts are enabled but that the
3626 * port has been hung up. Need to handle not having any TX buffer here,
3627 * this is done by using the side effect that head and tail will also
3628 * be NULL if the buffer has been freed.
3631 static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr)
3633 struct stlport *portp;
3636 unsigned char ioack, srer;
3638 pr_debug("stl_cd1400txisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3640 ioack = inb(ioaddr + EREG_TXACK);
3641 if (((ioack & panelp->ackmask) != 0) ||
3642 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
3643 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
3646 portp = panelp->ports[(ioack >> 3)];
3649 * Unfortunately we need to handle breaks in the data stream, since
3650 * this is the only way to generate them on the cd1400. Do it now if
3651 * a break is to be sent.
3653 if (portp->brklen != 0)
3654 if (stl_cd1400breakisr(portp, ioaddr))
3657 head = portp->tx.head;
3658 tail = portp->tx.tail;
3659 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
3660 if ((len == 0) || ((len < STL_TXBUFLOW) &&
3661 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
3662 set_bit(ASYI_TXLOW, &portp->istate);
3663 schedule_work(&portp->tqueue);
3667 outb((SRER + portp->uartaddr), ioaddr);
3668 srer = inb(ioaddr + EREG_DATA);
3669 if (srer & SRER_TXDATA) {
3670 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
3672 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
3673 clear_bit(ASYI_TXBUSY, &portp->istate);
3675 outb(srer, (ioaddr + EREG_DATA));
3677 len = MIN(len, CD1400_TXFIFOSIZE);
3678 portp->stats.txtotal += len;
3679 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
3680 outb((TDR + portp->uartaddr), ioaddr);
3681 outsb((ioaddr + EREG_DATA), tail, stlen);
3684 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
3685 tail = portp->tx.buf;
3687 outsb((ioaddr + EREG_DATA), tail, len);
3690 portp->tx.tail = tail;
3694 outb((EOSRR + portp->uartaddr), ioaddr);
3695 outb(0, (ioaddr + EREG_DATA));
3698 /*****************************************************************************/
3701 * Receive character interrupt handler. Determine if we have good chars
3702 * or bad chars and then process appropriately. Good chars are easy
3703 * just shove the lot into the RX buffer and set all status byte to 0.
3704 * If a bad RX char then process as required. This routine needs to be
3705 * fast! In practice it is possible that we get an interrupt on a port
3706 * that is closed. This can happen on hangups - since they completely
3707 * shutdown a port not in user context. Need to handle this case.
3710 static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr)
3712 struct stlport *portp;
3713 struct tty_struct *tty;
3714 unsigned int ioack, len, buflen;
3715 unsigned char status;
3718 pr_debug("stl_cd1400rxisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3720 ioack = inb(ioaddr + EREG_RXACK);
3721 if ((ioack & panelp->ackmask) != 0) {
3722 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
3725 portp = panelp->ports[(ioack >> 3)];
3728 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
3729 outb((RDCR + portp->uartaddr), ioaddr);
3730 len = inb(ioaddr + EREG_DATA);
3731 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
3732 len = MIN(len, sizeof(stl_unwanted));
3733 outb((RDSR + portp->uartaddr), ioaddr);
3734 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
3735 portp->stats.rxlost += len;
3736 portp->stats.rxtotal += len;
3738 len = MIN(len, buflen);
3741 outb((RDSR + portp->uartaddr), ioaddr);
3742 tty_prepare_flip_string(tty, &ptr, len);
3743 insb((ioaddr + EREG_DATA), ptr, len);
3744 tty_schedule_flip(tty);
3745 portp->stats.rxtotal += len;
3748 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
3749 outb((RDSR + portp->uartaddr), ioaddr);
3750 status = inb(ioaddr + EREG_DATA);
3751 ch = inb(ioaddr + EREG_DATA);
3752 if (status & ST_PARITY)
3753 portp->stats.rxparity++;
3754 if (status & ST_FRAMING)
3755 portp->stats.rxframing++;
3756 if (status & ST_OVERRUN)
3757 portp->stats.rxoverrun++;
3758 if (status & ST_BREAK)
3759 portp->stats.rxbreaks++;
3760 if (status & ST_SCHARMASK) {
3761 if ((status & ST_SCHARMASK) == ST_SCHAR1)
3762 portp->stats.txxon++;
3763 if ((status & ST_SCHARMASK) == ST_SCHAR2)
3764 portp->stats.txxoff++;
3767 if (tty != NULL && (portp->rxignoremsk & status) == 0) {
3768 if (portp->rxmarkmsk & status) {
3769 if (status & ST_BREAK) {
3771 if (portp->flags & ASYNC_SAK) {
3773 BRDENABLE(portp->brdnr, portp->pagenr);
3775 } else if (status & ST_PARITY) {
3776 status = TTY_PARITY;
3777 } else if (status & ST_FRAMING) {
3779 } else if(status & ST_OVERRUN) {
3780 status = TTY_OVERRUN;
3787 tty_insert_flip_char(tty, ch, status);
3788 tty_schedule_flip(tty);
3791 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
3796 outb((EOSRR + portp->uartaddr), ioaddr);
3797 outb(0, (ioaddr + EREG_DATA));
3800 /*****************************************************************************/
3803 * Modem interrupt handler. The is called when the modem signal line
3804 * (DCD) has changed state. Leave most of the work to the off-level
3805 * processing routine.
3808 static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr)
3810 struct stlport *portp;
3814 pr_debug("stl_cd1400mdmisr(panelp=%p)\n", panelp);
3816 ioack = inb(ioaddr + EREG_MDACK);
3817 if (((ioack & panelp->ackmask) != 0) ||
3818 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
3819 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
3822 portp = panelp->ports[(ioack >> 3)];
3824 outb((MISR + portp->uartaddr), ioaddr);
3825 misr = inb(ioaddr + EREG_DATA);
3826 if (misr & MISR_DCD) {
3827 set_bit(ASYI_DCDCHANGE, &portp->istate);
3828 schedule_work(&portp->tqueue);
3829 portp->stats.modem++;
3832 outb((EOSRR + portp->uartaddr), ioaddr);
3833 outb(0, (ioaddr + EREG_DATA));
3836 /*****************************************************************************/
3837 /* SC26198 HARDWARE FUNCTIONS */
3838 /*****************************************************************************/
3841 * These functions get/set/update the registers of the sc26198 UARTs.
3842 * Access to the sc26198 registers is via an address/data io port pair.
3843 * (Maybe should make this inline...)
3846 static int stl_sc26198getreg(struct stlport *portp, int regnr)
3848 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3849 return inb(portp->ioaddr + XP_DATA);
3852 static void stl_sc26198setreg(struct stlport *portp, int regnr, int value)
3854 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3855 outb(value, (portp->ioaddr + XP_DATA));
3858 static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value)
3860 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3861 if (inb(portp->ioaddr + XP_DATA) != value) {
3862 outb(value, (portp->ioaddr + XP_DATA));
3868 /*****************************************************************************/
3871 * Functions to get and set the sc26198 global registers.
3874 static int stl_sc26198getglobreg(struct stlport *portp, int regnr)
3876 outb(regnr, (portp->ioaddr + XP_ADDR));
3877 return inb(portp->ioaddr + XP_DATA);
3881 static void stl_sc26198setglobreg(struct stlport *portp, int regnr, int value)
3883 outb(regnr, (portp->ioaddr + XP_ADDR));
3884 outb(value, (portp->ioaddr + XP_DATA));
3888 /*****************************************************************************/
3891 * Inbitialize the UARTs in a panel. We don't care what sort of board
3892 * these ports are on - since the port io registers are almost
3893 * identical when dealing with ports.
3896 static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
3899 int nrchips, ioaddr;
3901 pr_debug("stl_sc26198panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
3903 BRDENABLE(panelp->brdnr, panelp->pagenr);
3906 * Check that each chip is present and started up OK.
3909 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
3910 if (brdp->brdtype == BRD_ECHPCI)
3911 outb(panelp->pagenr, brdp->ioctrl);
3913 for (i = 0; (i < nrchips); i++) {
3914 ioaddr = panelp->iobase + (i * 4);
3915 outb(SCCR, (ioaddr + XP_ADDR));
3916 outb(CR_RESETALL, (ioaddr + XP_DATA));
3917 outb(TSTR, (ioaddr + XP_ADDR));
3918 if (inb(ioaddr + XP_DATA) != 0) {
3919 printk("STALLION: sc26198 not responding, "
3920 "brd=%d panel=%d chip=%d\n",
3921 panelp->brdnr, panelp->panelnr, i);
3924 chipmask |= (0x1 << i);
3925 outb(GCCR, (ioaddr + XP_ADDR));
3926 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
3927 outb(WDTRCR, (ioaddr + XP_ADDR));
3928 outb(0xff, (ioaddr + XP_DATA));
3931 BRDDISABLE(panelp->brdnr);
3935 /*****************************************************************************/
3938 * Initialize hardware specific port registers.
3941 static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
3943 pr_debug("stl_sc26198portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
3946 if ((brdp == NULL) || (panelp == NULL) ||
3950 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
3951 portp->uartaddr = (portp->portnr & 0x07) << 4;
3952 portp->pagenr = panelp->pagenr;
3955 BRDENABLE(portp->brdnr, portp->pagenr);
3956 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
3957 BRDDISABLE(portp->brdnr);
3960 /*****************************************************************************/
3963 * Set up the sc26198 registers for a port based on the termios port
3967 static void stl_sc26198setport(struct stlport *portp, struct termios *tiosp)
3969 struct stlbrd *brdp;
3970 unsigned long flags;
3971 unsigned int baudrate;
3972 unsigned char mr0, mr1, mr2, clk;
3973 unsigned char imron, imroff, iopr, ipr;
3983 brdp = stl_brds[portp->brdnr];
3988 * Set up the RX char ignore mask with those RX error types we
3991 portp->rxignoremsk = 0;
3992 if (tiosp->c_iflag & IGNPAR)
3993 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
3995 if (tiosp->c_iflag & IGNBRK)
3996 portp->rxignoremsk |= SR_RXBREAK;
3998 portp->rxmarkmsk = SR_RXOVERRUN;
3999 if (tiosp->c_iflag & (INPCK | PARMRK))
4000 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
4001 if (tiosp->c_iflag & BRKINT)
4002 portp->rxmarkmsk |= SR_RXBREAK;
4005 * Go through the char size, parity and stop bits and set all the
4006 * option register appropriately.
4008 switch (tiosp->c_cflag & CSIZE) {
4023 if (tiosp->c_cflag & CSTOPB)
4028 if (tiosp->c_cflag & PARENB) {
4029 if (tiosp->c_cflag & PARODD)
4030 mr1 |= (MR1_PARENB | MR1_PARODD);
4032 mr1 |= (MR1_PARENB | MR1_PAREVEN);
4037 mr1 |= MR1_ERRBLOCK;
4040 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4041 * space for hardware flow control and the like. This should be set to
4044 mr2 |= MR2_RXFIFOHALF;
4047 * Calculate the baud rate timers. For now we will just assume that
4048 * the input and output baud are the same. The sc26198 has a fixed
4049 * baud rate table, so only discrete baud rates possible.
4051 baudrate = tiosp->c_cflag & CBAUD;
4052 if (baudrate & CBAUDEX) {
4053 baudrate &= ~CBAUDEX;
4054 if ((baudrate < 1) || (baudrate > 4))
4055 tiosp->c_cflag &= ~CBAUDEX;
4059 baudrate = stl_baudrates[baudrate];
4060 if ((tiosp->c_cflag & CBAUD) == B38400) {
4061 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
4063 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
4065 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
4067 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
4069 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
4070 baudrate = (portp->baud_base / portp->custom_divisor);
4072 if (baudrate > STL_SC26198MAXBAUD)
4073 baudrate = STL_SC26198MAXBAUD;
4076 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
4077 if (baudrate <= sc26198_baudtable[clk])
4083 * Check what form of modem signaling is required and set it up.
4085 if (tiosp->c_cflag & CLOCAL) {
4086 portp->flags &= ~ASYNC_CHECK_CD;
4088 iopr |= IOPR_DCDCOS;
4090 portp->flags |= ASYNC_CHECK_CD;
4094 * Setup sc26198 enhanced modes if we can. In particular we want to
4095 * handle as much of the flow control as possible automatically. As
4096 * well as saving a few CPU cycles it will also greatly improve flow
4097 * control reliability.
4099 if (tiosp->c_iflag & IXON) {
4100 mr0 |= MR0_SWFTX | MR0_SWFT;
4101 imron |= IR_XONXOFF;
4103 imroff |= IR_XONXOFF;
4105 if (tiosp->c_iflag & IXOFF)
4108 if (tiosp->c_cflag & CRTSCTS) {
4114 * All sc26198 register values calculated so go through and set
4118 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4119 portp->portnr, portp->panelnr, portp->brdnr);
4120 pr_debug(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4121 pr_debug(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4122 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4123 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4124 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4126 spin_lock_irqsave(&brd_lock, flags);
4127 BRDENABLE(portp->brdnr, portp->pagenr);
4128 stl_sc26198setreg(portp, IMR, 0);
4129 stl_sc26198updatereg(portp, MR0, mr0);
4130 stl_sc26198updatereg(portp, MR1, mr1);
4131 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4132 stl_sc26198updatereg(portp, MR2, mr2);
4133 stl_sc26198updatereg(portp, IOPIOR,
4134 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
4137 stl_sc26198setreg(portp, TXCSR, clk);
4138 stl_sc26198setreg(portp, RXCSR, clk);
4141 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4142 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4144 ipr = stl_sc26198getreg(portp, IPR);
4146 portp->sigs &= ~TIOCM_CD;
4148 portp->sigs |= TIOCM_CD;
4150 portp->imr = (portp->imr & ~imroff) | imron;
4151 stl_sc26198setreg(portp, IMR, portp->imr);
4152 BRDDISABLE(portp->brdnr);
4153 spin_unlock_irqrestore(&brd_lock, flags);
4156 /*****************************************************************************/
4159 * Set the state of the DTR and RTS signals.
4162 static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts)
4164 unsigned char iopioron, iopioroff;
4165 unsigned long flags;
4167 pr_debug("stl_sc26198setsignals(portp=%p,dtr=%d,rts=%d)\n", portp,
4173 iopioroff |= IPR_DTR;
4175 iopioron |= IPR_DTR;
4177 iopioroff |= IPR_RTS;
4179 iopioron |= IPR_RTS;
4181 spin_lock_irqsave(&brd_lock, flags);
4182 BRDENABLE(portp->brdnr, portp->pagenr);
4183 stl_sc26198setreg(portp, IOPIOR,
4184 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4185 BRDDISABLE(portp->brdnr);
4186 spin_unlock_irqrestore(&brd_lock, flags);
4189 /*****************************************************************************/
4192 * Return the state of the signals.
4195 static int stl_sc26198getsignals(struct stlport *portp)
4198 unsigned long flags;
4201 pr_debug("stl_sc26198getsignals(portp=%p)\n", portp);
4203 spin_lock_irqsave(&brd_lock, flags);
4204 BRDENABLE(portp->brdnr, portp->pagenr);
4205 ipr = stl_sc26198getreg(portp, IPR);
4206 BRDDISABLE(portp->brdnr);
4207 spin_unlock_irqrestore(&brd_lock, flags);
4210 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4211 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4212 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4213 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4218 /*****************************************************************************/
4221 * Enable/Disable the Transmitter and/or Receiver.
4224 static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx)
4227 unsigned long flags;
4229 pr_debug("stl_sc26198enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx,tx);
4231 ccr = portp->crenable;
4233 ccr &= ~CR_TXENABLE;
4237 ccr &= ~CR_RXENABLE;
4241 spin_lock_irqsave(&brd_lock, flags);
4242 BRDENABLE(portp->brdnr, portp->pagenr);
4243 stl_sc26198setreg(portp, SCCR, ccr);
4244 BRDDISABLE(portp->brdnr);
4245 portp->crenable = ccr;
4246 spin_unlock_irqrestore(&brd_lock, flags);
4249 /*****************************************************************************/
4252 * Start/stop the Transmitter and/or Receiver.
4255 static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx)
4258 unsigned long flags;
4260 pr_debug("stl_sc26198startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
4268 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4270 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4272 spin_lock_irqsave(&brd_lock, flags);
4273 BRDENABLE(portp->brdnr, portp->pagenr);
4274 stl_sc26198setreg(portp, IMR, imr);
4275 BRDDISABLE(portp->brdnr);
4278 set_bit(ASYI_TXBUSY, &portp->istate);
4279 spin_unlock_irqrestore(&brd_lock, flags);
4282 /*****************************************************************************/
4285 * Disable all interrupts from this port.
4288 static void stl_sc26198disableintrs(struct stlport *portp)
4290 unsigned long flags;
4292 pr_debug("stl_sc26198disableintrs(portp=%p)\n", portp);
4294 spin_lock_irqsave(&brd_lock, flags);
4295 BRDENABLE(portp->brdnr, portp->pagenr);
4297 stl_sc26198setreg(portp, IMR, 0);
4298 BRDDISABLE(portp->brdnr);
4299 spin_unlock_irqrestore(&brd_lock, flags);
4302 /*****************************************************************************/
4304 static void stl_sc26198sendbreak(struct stlport *portp, int len)
4306 unsigned long flags;
4308 pr_debug("stl_sc26198sendbreak(portp=%p,len=%d)\n", portp, len);
4310 spin_lock_irqsave(&brd_lock, flags);
4311 BRDENABLE(portp->brdnr, portp->pagenr);
4313 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4314 portp->stats.txbreaks++;
4316 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4318 BRDDISABLE(portp->brdnr);
4319 spin_unlock_irqrestore(&brd_lock, flags);
4322 /*****************************************************************************/
4325 * Take flow control actions...
4328 static void stl_sc26198flowctrl(struct stlport *portp, int state)
4330 struct tty_struct *tty;
4331 unsigned long flags;
4334 pr_debug("stl_sc26198flowctrl(portp=%p,state=%x)\n", portp, state);
4342 spin_lock_irqsave(&brd_lock, flags);
4343 BRDENABLE(portp->brdnr, portp->pagenr);
4346 if (tty->termios->c_iflag & IXOFF) {
4347 mr0 = stl_sc26198getreg(portp, MR0);
4348 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4349 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4351 portp->stats.rxxon++;
4352 stl_sc26198wait(portp);
4353 stl_sc26198setreg(portp, MR0, mr0);
4356 * Question: should we return RTS to what it was before? It may
4357 * have been set by an ioctl... Suppose not, since if you have
4358 * hardware flow control set then it is pretty silly to go and
4359 * set the RTS line by hand.
4361 if (tty->termios->c_cflag & CRTSCTS) {
4362 stl_sc26198setreg(portp, MR1,
4363 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4364 stl_sc26198setreg(portp, IOPIOR,
4365 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4366 portp->stats.rxrtson++;
4369 if (tty->termios->c_iflag & IXOFF) {
4370 mr0 = stl_sc26198getreg(portp, MR0);
4371 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4372 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4374 portp->stats.rxxoff++;
4375 stl_sc26198wait(portp);
4376 stl_sc26198setreg(portp, MR0, mr0);
4378 if (tty->termios->c_cflag & CRTSCTS) {
4379 stl_sc26198setreg(portp, MR1,
4380 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4381 stl_sc26198setreg(portp, IOPIOR,
4382 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4383 portp->stats.rxrtsoff++;
4387 BRDDISABLE(portp->brdnr);
4388 spin_unlock_irqrestore(&brd_lock, flags);
4391 /*****************************************************************************/
4394 * Send a flow control character.
4397 static void stl_sc26198sendflow(struct stlport *portp, int state)
4399 struct tty_struct *tty;
4400 unsigned long flags;
4403 pr_debug("stl_sc26198sendflow(portp=%p,state=%x)\n", portp, state);
4411 spin_lock_irqsave(&brd_lock, flags);
4412 BRDENABLE(portp->brdnr, portp->pagenr);
4414 mr0 = stl_sc26198getreg(portp, MR0);
4415 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4416 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4418 portp->stats.rxxon++;
4419 stl_sc26198wait(portp);
4420 stl_sc26198setreg(portp, MR0, mr0);
4422 mr0 = stl_sc26198getreg(portp, MR0);
4423 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4424 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4426 portp->stats.rxxoff++;
4427 stl_sc26198wait(portp);
4428 stl_sc26198setreg(portp, MR0, mr0);
4430 BRDDISABLE(portp->brdnr);
4431 spin_unlock_irqrestore(&brd_lock, flags);
4434 /*****************************************************************************/
4436 static void stl_sc26198flush(struct stlport *portp)
4438 unsigned long flags;
4440 pr_debug("stl_sc26198flush(portp=%p)\n", portp);
4445 spin_lock_irqsave(&brd_lock, flags);
4446 BRDENABLE(portp->brdnr, portp->pagenr);
4447 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4448 stl_sc26198setreg(portp, SCCR, portp->crenable);
4449 BRDDISABLE(portp->brdnr);
4450 portp->tx.tail = portp->tx.head;
4451 spin_unlock_irqrestore(&brd_lock, flags);
4454 /*****************************************************************************/
4457 * Return the current state of data flow on this port. This is only
4458 * really interresting when determining if data has fully completed
4459 * transmission or not... The sc26198 interrupt scheme cannot
4460 * determine when all data has actually drained, so we need to
4461 * check the port statusy register to be sure.
4464 static int stl_sc26198datastate(struct stlport *portp)
4466 unsigned long flags;
4469 pr_debug("stl_sc26198datastate(portp=%p)\n", portp);
4473 if (test_bit(ASYI_TXBUSY, &portp->istate))
4476 spin_lock_irqsave(&brd_lock, flags);
4477 BRDENABLE(portp->brdnr, portp->pagenr);
4478 sr = stl_sc26198getreg(portp, SR);
4479 BRDDISABLE(portp->brdnr);
4480 spin_unlock_irqrestore(&brd_lock, flags);
4482 return (sr & SR_TXEMPTY) ? 0 : 1;
4485 /*****************************************************************************/
4488 * Delay for a small amount of time, to give the sc26198 a chance
4489 * to process a command...
4492 static void stl_sc26198wait(struct stlport *portp)
4496 pr_debug("stl_sc26198wait(portp=%p)\n", portp);
4501 for (i = 0; (i < 20); i++)
4502 stl_sc26198getglobreg(portp, TSTR);
4505 /*****************************************************************************/
4508 * If we are TX flow controlled and in IXANY mode then we may
4509 * need to unflow control here. We gotta do this because of the
4510 * automatic flow control modes of the sc26198.
4513 static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty)
4517 mr0 = stl_sc26198getreg(portp, MR0);
4518 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4519 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4520 stl_sc26198wait(portp);
4521 stl_sc26198setreg(portp, MR0, mr0);
4522 clear_bit(ASYI_TXFLOWED, &portp->istate);
4525 /*****************************************************************************/
4528 * Interrupt service routine for sc26198 panels.
4531 static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase)
4533 struct stlport *portp;
4536 spin_lock(&brd_lock);
4539 * Work around bug in sc26198 chip... Cannot have A6 address
4540 * line of UART high, else iack will be returned as 0.
4542 outb(0, (iobase + 1));
4544 iack = inb(iobase + XP_IACK);
4545 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4547 if (iack & IVR_RXDATA)
4548 stl_sc26198rxisr(portp, iack);
4549 else if (iack & IVR_TXDATA)
4550 stl_sc26198txisr(portp);
4552 stl_sc26198otherisr(portp, iack);
4554 spin_unlock(&brd_lock);
4557 /*****************************************************************************/
4560 * Transmit interrupt handler. This has gotta be fast! Handling TX
4561 * chars is pretty simple, stuff as many as possible from the TX buffer
4562 * into the sc26198 FIFO.
4563 * In practice it is possible that interrupts are enabled but that the
4564 * port has been hung up. Need to handle not having any TX buffer here,
4565 * this is done by using the side effect that head and tail will also
4566 * be NULL if the buffer has been freed.
4569 static void stl_sc26198txisr(struct stlport *portp)
4571 unsigned int ioaddr;
4576 pr_debug("stl_sc26198txisr(portp=%p)\n", portp);
4578 ioaddr = portp->ioaddr;
4579 head = portp->tx.head;
4580 tail = portp->tx.tail;
4581 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4582 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4583 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4584 set_bit(ASYI_TXLOW, &portp->istate);
4585 schedule_work(&portp->tqueue);
4589 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
4590 mr0 = inb(ioaddr + XP_DATA);
4591 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4592 portp->imr &= ~IR_TXRDY;
4593 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
4594 outb(portp->imr, (ioaddr + XP_DATA));
4595 clear_bit(ASYI_TXBUSY, &portp->istate);
4597 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4598 outb(mr0, (ioaddr + XP_DATA));
4601 len = MIN(len, SC26198_TXFIFOSIZE);
4602 portp->stats.txtotal += len;
4603 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4604 outb(GTXFIFO, (ioaddr + XP_ADDR));
4605 outsb((ioaddr + XP_DATA), tail, stlen);
4608 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4609 tail = portp->tx.buf;
4611 outsb((ioaddr + XP_DATA), tail, len);
4614 portp->tx.tail = tail;
4618 /*****************************************************************************/
4621 * Receive character interrupt handler. Determine if we have good chars
4622 * or bad chars and then process appropriately. Good chars are easy
4623 * just shove the lot into the RX buffer and set all status byte to 0.
4624 * If a bad RX char then process as required. This routine needs to be
4625 * fast! In practice it is possible that we get an interrupt on a port
4626 * that is closed. This can happen on hangups - since they completely
4627 * shutdown a port not in user context. Need to handle this case.
4630 static void stl_sc26198rxisr(struct stlport *portp, unsigned int iack)
4632 struct tty_struct *tty;
4633 unsigned int len, buflen, ioaddr;
4635 pr_debug("stl_sc26198rxisr(portp=%p,iack=%x)\n", portp, iack);
4638 ioaddr = portp->ioaddr;
4639 outb(GIBCR, (ioaddr + XP_ADDR));
4640 len = inb(ioaddr + XP_DATA) + 1;
4642 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
4643 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
4644 len = MIN(len, sizeof(stl_unwanted));
4645 outb(GRXFIFO, (ioaddr + XP_ADDR));
4646 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4647 portp->stats.rxlost += len;
4648 portp->stats.rxtotal += len;
4650 len = MIN(len, buflen);
4653 outb(GRXFIFO, (ioaddr + XP_ADDR));
4654 tty_prepare_flip_string(tty, &ptr, len);
4655 insb((ioaddr + XP_DATA), ptr, len);
4656 tty_schedule_flip(tty);
4657 portp->stats.rxtotal += len;
4661 stl_sc26198rxbadchars(portp);
4665 * If we are TX flow controlled and in IXANY mode then we may need
4666 * to unflow control here. We gotta do this because of the automatic
4667 * flow control modes of the sc26198.
4669 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
4670 if ((tty != NULL) &&
4671 (tty->termios != NULL) &&
4672 (tty->termios->c_iflag & IXANY)) {
4673 stl_sc26198txunflow(portp, tty);
4678 /*****************************************************************************/
4681 * Process an RX bad character.
4684 static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch)
4686 struct tty_struct *tty;
4687 unsigned int ioaddr;
4690 ioaddr = portp->ioaddr;
4692 if (status & SR_RXPARITY)
4693 portp->stats.rxparity++;
4694 if (status & SR_RXFRAMING)
4695 portp->stats.rxframing++;
4696 if (status & SR_RXOVERRUN)
4697 portp->stats.rxoverrun++;
4698 if (status & SR_RXBREAK)
4699 portp->stats.rxbreaks++;
4701 if ((tty != NULL) &&
4702 ((portp->rxignoremsk & status) == 0)) {
4703 if (portp->rxmarkmsk & status) {
4704 if (status & SR_RXBREAK) {
4706 if (portp->flags & ASYNC_SAK) {
4708 BRDENABLE(portp->brdnr, portp->pagenr);
4710 } else if (status & SR_RXPARITY) {
4711 status = TTY_PARITY;
4712 } else if (status & SR_RXFRAMING) {
4714 } else if(status & SR_RXOVERRUN) {
4715 status = TTY_OVERRUN;
4723 tty_insert_flip_char(tty, ch, status);
4724 tty_schedule_flip(tty);
4727 portp->stats.rxtotal++;
4731 /*****************************************************************************/
4734 * Process all characters in the RX FIFO of the UART. Check all char
4735 * status bytes as well, and process as required. We need to check
4736 * all bytes in the FIFO, in case some more enter the FIFO while we
4737 * are here. To get the exact character error type we need to switch
4738 * into CHAR error mode (that is why we need to make sure we empty
4742 static void stl_sc26198rxbadchars(struct stlport *portp)
4744 unsigned char status, mr1;
4748 * To get the precise error type for each character we must switch
4749 * back into CHAR error mode.
4751 mr1 = stl_sc26198getreg(portp, MR1);
4752 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
4754 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
4755 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
4756 ch = stl_sc26198getreg(portp, RXFIFO);
4757 stl_sc26198rxbadch(portp, status, ch);
4761 * To get correct interrupt class we must switch back into BLOCK
4764 stl_sc26198setreg(portp, MR1, mr1);
4767 /*****************************************************************************/
4770 * Other interrupt handler. This includes modem signals, flow
4771 * control actions, etc. Most stuff is left to off-level interrupt
4775 static void stl_sc26198otherisr(struct stlport *portp, unsigned int iack)
4777 unsigned char cir, ipr, xisr;
4779 pr_debug("stl_sc26198otherisr(portp=%p,iack=%x)\n", portp, iack);
4781 cir = stl_sc26198getglobreg(portp, CIR);
4783 switch (cir & CIR_SUBTYPEMASK) {
4785 ipr = stl_sc26198getreg(portp, IPR);
4786 if (ipr & IPR_DCDCHANGE) {
4787 set_bit(ASYI_DCDCHANGE, &portp->istate);
4788 schedule_work(&portp->tqueue);
4789 portp->stats.modem++;
4792 case CIR_SUBXONXOFF:
4793 xisr = stl_sc26198getreg(portp, XISR);
4794 if (xisr & XISR_RXXONGOT) {
4795 set_bit(ASYI_TXFLOWED, &portp->istate);
4796 portp->stats.txxoff++;
4798 if (xisr & XISR_RXXOFFGOT) {
4799 clear_bit(ASYI_TXFLOWED, &portp->istate);
4800 portp->stats.txxon++;
4804 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
4805 stl_sc26198rxbadchars(portp);
4813 * Loadable module initialization stuff.
4815 static int __init stallion_module_init(void)
4819 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
4821 spin_lock_init(&stallion_lock);
4822 spin_lock_init(&brd_lock);
4826 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
4831 * Set up a character driver for per board stuff. This is mainly used
4832 * to do stats ioctls on the ports.
4834 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
4835 printk("STALLION: failed to register serial board device\n");
4837 stallion_class = class_create(THIS_MODULE, "staliomem");
4838 for (i = 0; i < 4; i++)
4839 class_device_create(stallion_class, NULL,
4840 MKDEV(STL_SIOMEMMAJOR, i), NULL,
4843 stl_serial->owner = THIS_MODULE;
4844 stl_serial->driver_name = stl_drvname;
4845 stl_serial->name = "ttyE";
4846 stl_serial->major = STL_SERIALMAJOR;
4847 stl_serial->minor_start = 0;
4848 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
4849 stl_serial->subtype = SERIAL_TYPE_NORMAL;
4850 stl_serial->init_termios = stl_deftermios;
4851 stl_serial->flags = TTY_DRIVER_REAL_RAW;
4852 tty_set_operations(stl_serial, &stl_ops);
4854 if (tty_register_driver(stl_serial)) {
4855 put_tty_driver(stl_serial);
4856 printk("STALLION: failed to register serial driver\n");
4863 static void __exit stallion_module_exit(void)
4865 struct stlbrd *brdp;
4866 struct stlpanel *panelp;
4867 struct stlport *portp;
4870 pr_debug("cleanup_module()\n");
4872 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
4876 * Free up all allocated resources used by the ports. This includes
4877 * memory and interrupts. As part of this process we will also do
4878 * a hangup on every open port - to try to flush out any processes
4879 * hanging onto ports.
4881 i = tty_unregister_driver(stl_serial);
4882 put_tty_driver(stl_serial);
4884 printk("STALLION: failed to un-register tty driver, "
4888 for (i = 0; i < 4; i++)
4889 class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
4890 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
4891 printk("STALLION: failed to un-register serial memory device, "
4893 class_destroy(stallion_class);
4895 for (i = 0; (i < stl_nrbrds); i++) {
4896 if ((brdp = stl_brds[i]) == NULL)
4899 free_irq(brdp->irq, brdp);
4901 for (j = 0; (j < STL_MAXPANELS); j++) {
4902 panelp = brdp->panels[j];
4905 for (k = 0; (k < STL_PORTSPERPANEL); k++) {
4906 portp = panelp->ports[k];
4909 if (portp->tty != NULL)
4910 stl_hangup(portp->tty);
4911 kfree(portp->tx.buf);
4917 release_region(brdp->ioaddr1, brdp->iosize1);
4918 if (brdp->iosize2 > 0)
4919 release_region(brdp->ioaddr2, brdp->iosize2);
4926 module_init(stallion_module_init);
4927 module_exit(stallion_module_exit);
4929 MODULE_AUTHOR("Greg Ungerer");
4930 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
4931 MODULE_LICENSE("GPL");