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 int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
454 static int stl_brdinit(struct stlbrd *brdp);
455 static int stl_getportstats(struct stlport *portp, comstats_t __user *cp);
456 static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp);
457 static int stl_waitcarrier(struct stlport *portp, struct file *filp);
460 * CD1400 uart specific handling functions.
462 static void stl_cd1400setreg(struct stlport *portp, int regnr, int value);
463 static int stl_cd1400getreg(struct stlport *portp, int regnr);
464 static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value);
465 static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
466 static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
467 static void stl_cd1400setport(struct stlport *portp, struct termios *tiosp);
468 static int stl_cd1400getsignals(struct stlport *portp);
469 static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts);
470 static void stl_cd1400ccrwait(struct stlport *portp);
471 static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx);
472 static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx);
473 static void stl_cd1400disableintrs(struct stlport *portp);
474 static void stl_cd1400sendbreak(struct stlport *portp, int len);
475 static void stl_cd1400flowctrl(struct stlport *portp, int state);
476 static void stl_cd1400sendflow(struct stlport *portp, int state);
477 static void stl_cd1400flush(struct stlport *portp);
478 static int stl_cd1400datastate(struct stlport *portp);
479 static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase);
480 static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase);
481 static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr);
482 static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr);
483 static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr);
485 static inline int stl_cd1400breakisr(struct stlport *portp, int ioaddr);
488 * SC26198 uart specific handling functions.
490 static void stl_sc26198setreg(struct stlport *portp, int regnr, int value);
491 static int stl_sc26198getreg(struct stlport *portp, int regnr);
492 static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value);
493 static int stl_sc26198getglobreg(struct stlport *portp, int regnr);
494 static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
495 static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
496 static void stl_sc26198setport(struct stlport *portp, struct termios *tiosp);
497 static int stl_sc26198getsignals(struct stlport *portp);
498 static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts);
499 static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx);
500 static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx);
501 static void stl_sc26198disableintrs(struct stlport *portp);
502 static void stl_sc26198sendbreak(struct stlport *portp, int len);
503 static void stl_sc26198flowctrl(struct stlport *portp, int state);
504 static void stl_sc26198sendflow(struct stlport *portp, int state);
505 static void stl_sc26198flush(struct stlport *portp);
506 static int stl_sc26198datastate(struct stlport *portp);
507 static void stl_sc26198wait(struct stlport *portp);
508 static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty);
509 static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase);
510 static void stl_sc26198txisr(struct stlport *port);
511 static void stl_sc26198rxisr(struct stlport *port, unsigned int iack);
512 static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch);
513 static void stl_sc26198rxbadchars(struct stlport *portp);
514 static void stl_sc26198otherisr(struct stlport *port, unsigned int iack);
516 /*****************************************************************************/
519 * Generic UART support structure.
521 typedef struct uart {
522 int (*panelinit)(struct stlbrd *brdp, struct stlpanel *panelp);
523 void (*portinit)(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
524 void (*setport)(struct stlport *portp, struct termios *tiosp);
525 int (*getsignals)(struct stlport *portp);
526 void (*setsignals)(struct stlport *portp, int dtr, int rts);
527 void (*enablerxtx)(struct stlport *portp, int rx, int tx);
528 void (*startrxtx)(struct stlport *portp, int rx, int tx);
529 void (*disableintrs)(struct stlport *portp);
530 void (*sendbreak)(struct stlport *portp, int len);
531 void (*flowctrl)(struct stlport *portp, int state);
532 void (*sendflow)(struct stlport *portp, int state);
533 void (*flush)(struct stlport *portp);
534 int (*datastate)(struct stlport *portp);
535 void (*intr)(struct stlpanel *panelp, unsigned int iobase);
539 * Define some macros to make calling these functions nice and clean.
541 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
542 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
543 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
544 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
545 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
546 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
547 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
548 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
549 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
550 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
551 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
552 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
553 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
555 /*****************************************************************************/
558 * CD1400 UART specific data initialization.
560 static uart_t stl_cd1400uart = {
564 stl_cd1400getsignals,
565 stl_cd1400setsignals,
566 stl_cd1400enablerxtx,
568 stl_cd1400disableintrs,
578 * Define the offsets within the register bank of a cd1400 based panel.
579 * These io address offsets are common to the EasyIO board as well.
587 #define EREG_BANKSIZE 8
589 #define CD1400_CLK 25000000
590 #define CD1400_CLK8M 20000000
593 * Define the cd1400 baud rate clocks. These are used when calculating
594 * what clock and divisor to use for the required baud rate. Also
595 * define the maximum baud rate allowed, and the default base baud.
597 static int stl_cd1400clkdivs[] = {
598 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
601 /*****************************************************************************/
604 * SC26198 UART specific data initization.
606 static uart_t stl_sc26198uart = {
607 stl_sc26198panelinit,
610 stl_sc26198getsignals,
611 stl_sc26198setsignals,
612 stl_sc26198enablerxtx,
613 stl_sc26198startrxtx,
614 stl_sc26198disableintrs,
615 stl_sc26198sendbreak,
619 stl_sc26198datastate,
624 * Define the offsets within the register bank of a sc26198 based panel.
632 #define XP_BANKSIZE 4
635 * Define the sc26198 baud rate table. Offsets within the table
636 * represent the actual baud rate selector of sc26198 registers.
638 static unsigned int sc26198_baudtable[] = {
639 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
640 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
641 230400, 460800, 921600
644 #define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
646 /*****************************************************************************/
649 * Define the driver info for a user level control device. Used mainly
650 * to get at port stats - only not using the port device itself.
652 static const struct file_operations stl_fsiomem = {
653 .owner = THIS_MODULE,
654 .ioctl = stl_memioctl,
657 static struct class *stallion_class;
660 * Check for any arguments passed in on the module load command line.
663 /*****************************************************************************/
666 * Convert an ascii string number into an unsigned long.
669 static unsigned long stl_atol(char *str)
677 if ((*sp == '0') && (*(sp+1) == 'x')) {
680 } else if (*sp == '0') {
687 for (; (*sp != 0); sp++) {
688 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
689 if ((c < 0) || (c >= base)) {
690 printk("STALLION: invalid argument %s\n", str);
694 val = (val * base) + c;
699 /*****************************************************************************/
702 * Parse the supplied argument string, into the board conf struct.
705 static int __init stl_parsebrd(struct stlconf *confp, char **argp)
710 pr_debug("stl_parsebrd(confp=%p,argp=%p)\n", confp, argp);
712 if ((argp[0] == NULL) || (*argp[0] == 0))
715 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
718 for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++) {
719 if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
722 if (i == ARRAY_SIZE(stl_brdstr)) {
723 printk("STALLION: unknown board name, %s?\n", argp[0]);
727 confp->brdtype = stl_brdstr[i].type;
730 if ((argp[i] != NULL) && (*argp[i] != 0))
731 confp->ioaddr1 = stl_atol(argp[i]);
733 if (confp->brdtype == BRD_ECH) {
734 if ((argp[i] != NULL) && (*argp[i] != 0))
735 confp->ioaddr2 = stl_atol(argp[i]);
738 if ((argp[i] != NULL) && (*argp[i] != 0))
739 confp->irq = stl_atol(argp[i]);
743 /*****************************************************************************/
746 * Allocate a new board structure. Fill out the basic info in it.
749 static struct stlbrd *stl_allocbrd(void)
753 brdp = kzalloc(sizeof(struct stlbrd), GFP_KERNEL);
755 printk("STALLION: failed to allocate memory (size=%Zd)\n",
756 sizeof(struct stlbrd));
760 brdp->magic = STL_BOARDMAGIC;
764 static void __init stl_argbrds(void)
770 pr_debug("stl_argbrds()\n");
772 for (i = stl_nrbrds; (i < stl_nargs); i++) {
773 memset(&conf, 0, sizeof(conf));
774 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
776 if ((brdp = stl_allocbrd()) == NULL)
780 brdp->brdtype = conf.brdtype;
781 brdp->ioaddr1 = conf.ioaddr1;
782 brdp->ioaddr2 = conf.ioaddr2;
783 brdp->irq = conf.irq;
784 brdp->irqtype = conf.irqtype;
789 /*****************************************************************************/
791 static int stl_open(struct tty_struct *tty, struct file *filp)
793 struct stlport *portp;
795 unsigned int minordev;
796 int brdnr, panelnr, portnr, rc;
798 pr_debug("stl_open(tty=%p,filp=%p): device=%s\n", tty, filp, tty->name);
800 minordev = tty->index;
801 brdnr = MINOR2BRD(minordev);
802 if (brdnr >= stl_nrbrds)
804 brdp = stl_brds[brdnr];
807 minordev = MINOR2PORT(minordev);
808 for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
809 if (brdp->panels[panelnr] == NULL)
811 if (minordev < brdp->panels[panelnr]->nrports) {
815 minordev -= brdp->panels[panelnr]->nrports;
820 portp = brdp->panels[panelnr]->ports[portnr];
825 * On the first open of the device setup the port hardware, and
826 * initialize the per port data structure.
829 tty->driver_data = portp;
832 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
833 if (!portp->tx.buf) {
834 portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
837 portp->tx.head = portp->tx.buf;
838 portp->tx.tail = portp->tx.buf;
840 stl_setport(portp, tty->termios);
841 portp->sigs = stl_getsignals(portp);
842 stl_setsignals(portp, 1, 1);
843 stl_enablerxtx(portp, 1, 1);
844 stl_startrxtx(portp, 1, 0);
845 clear_bit(TTY_IO_ERROR, &tty->flags);
846 portp->flags |= ASYNC_INITIALIZED;
850 * Check if this port is in the middle of closing. If so then wait
851 * until it is closed then return error status, based on flag settings.
852 * The sleep here does not need interrupt protection since the wakeup
853 * for it is done with the same context.
855 if (portp->flags & ASYNC_CLOSING) {
856 interruptible_sleep_on(&portp->close_wait);
857 if (portp->flags & ASYNC_HUP_NOTIFY)
863 * Based on type of open being done check if it can overlap with any
864 * previous opens still in effect. If we are a normal serial device
865 * then also we might have to wait for carrier.
867 if (!(filp->f_flags & O_NONBLOCK)) {
868 if ((rc = stl_waitcarrier(portp, filp)) != 0)
871 portp->flags |= ASYNC_NORMAL_ACTIVE;
876 /*****************************************************************************/
879 * Possibly need to wait for carrier (DCD signal) to come high. Say
880 * maybe because if we are clocal then we don't need to wait...
883 static int stl_waitcarrier(struct stlport *portp, struct file *filp)
888 pr_debug("stl_waitcarrier(portp=%p,filp=%p)\n", portp, filp);
893 spin_lock_irqsave(&stallion_lock, flags);
895 if (portp->tty->termios->c_cflag & CLOCAL)
898 portp->openwaitcnt++;
899 if (! tty_hung_up_p(filp))
903 /* Takes brd_lock internally */
904 stl_setsignals(portp, 1, 1);
905 if (tty_hung_up_p(filp) ||
906 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
907 if (portp->flags & ASYNC_HUP_NOTIFY)
913 if (((portp->flags & ASYNC_CLOSING) == 0) &&
914 (doclocal || (portp->sigs & TIOCM_CD))) {
917 if (signal_pending(current)) {
922 interruptible_sleep_on(&portp->open_wait);
925 if (! tty_hung_up_p(filp))
927 portp->openwaitcnt--;
928 spin_unlock_irqrestore(&stallion_lock, flags);
933 /*****************************************************************************/
935 static void stl_flushbuffer(struct tty_struct *tty)
937 struct stlport *portp;
939 pr_debug("stl_flushbuffer(tty=%p)\n", tty);
943 portp = tty->driver_data;
951 /*****************************************************************************/
953 static void stl_waituntilsent(struct tty_struct *tty, int timeout)
955 struct stlport *portp;
958 pr_debug("stl_waituntilsent(tty=%p,timeout=%d)\n", tty, timeout);
962 portp = tty->driver_data;
968 tend = jiffies + timeout;
970 while (stl_datastate(portp)) {
971 if (signal_pending(current))
973 msleep_interruptible(20);
974 if (time_after_eq(jiffies, tend))
979 /*****************************************************************************/
981 static void stl_close(struct tty_struct *tty, struct file *filp)
983 struct stlport *portp;
986 pr_debug("stl_close(tty=%p,filp=%p)\n", tty, filp);
988 portp = tty->driver_data;
992 spin_lock_irqsave(&stallion_lock, flags);
993 if (tty_hung_up_p(filp)) {
994 spin_unlock_irqrestore(&stallion_lock, flags);
997 if ((tty->count == 1) && (portp->refcount != 1))
999 if (portp->refcount-- > 1) {
1000 spin_unlock_irqrestore(&stallion_lock, flags);
1004 portp->refcount = 0;
1005 portp->flags |= ASYNC_CLOSING;
1008 * May want to wait for any data to drain before closing. The BUSY
1009 * flag keeps track of whether we are still sending or not - it is
1010 * very accurate for the cd1400, not quite so for the sc26198.
1011 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1015 spin_unlock_irqrestore(&stallion_lock, flags);
1017 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1018 tty_wait_until_sent(tty, portp->closing_wait);
1019 stl_waituntilsent(tty, (HZ / 2));
1022 spin_lock_irqsave(&stallion_lock, flags);
1023 portp->flags &= ~ASYNC_INITIALIZED;
1024 spin_unlock_irqrestore(&stallion_lock, flags);
1026 stl_disableintrs(portp);
1027 if (tty->termios->c_cflag & HUPCL)
1028 stl_setsignals(portp, 0, 0);
1029 stl_enablerxtx(portp, 0, 0);
1030 stl_flushbuffer(tty);
1032 if (portp->tx.buf != NULL) {
1033 kfree(portp->tx.buf);
1034 portp->tx.buf = NULL;
1035 portp->tx.head = NULL;
1036 portp->tx.tail = NULL;
1038 set_bit(TTY_IO_ERROR, &tty->flags);
1039 tty_ldisc_flush(tty);
1044 if (portp->openwaitcnt) {
1045 if (portp->close_delay)
1046 msleep_interruptible(jiffies_to_msecs(portp->close_delay));
1047 wake_up_interruptible(&portp->open_wait);
1050 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1051 wake_up_interruptible(&portp->close_wait);
1054 /*****************************************************************************/
1057 * Write routine. Take data and stuff it in to the TX ring queue.
1058 * If transmit interrupts are not running then start them.
1061 static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
1063 struct stlport *portp;
1064 unsigned int len, stlen;
1065 unsigned char *chbuf;
1068 pr_debug("stl_write(tty=%p,buf=%p,count=%d)\n", tty, buf, count);
1070 portp = tty->driver_data;
1073 if (portp->tx.buf == NULL)
1077 * If copying direct from user space we must cater for page faults,
1078 * causing us to "sleep" here for a while. To handle this copy in all
1079 * the data we need now, into a local buffer. Then when we got it all
1080 * copy it into the TX buffer.
1082 chbuf = (unsigned char *) buf;
1084 head = portp->tx.head;
1085 tail = portp->tx.tail;
1087 len = STL_TXBUFSIZE - (head - tail) - 1;
1088 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
1090 len = tail - head - 1;
1094 len = MIN(len, count);
1097 stlen = MIN(len, stlen);
1098 memcpy(head, chbuf, stlen);
1103 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
1104 head = portp->tx.buf;
1105 stlen = tail - head;
1108 portp->tx.head = head;
1110 clear_bit(ASYI_TXLOW, &portp->istate);
1111 stl_startrxtx(portp, -1, 1);
1116 /*****************************************************************************/
1118 static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1120 struct stlport *portp;
1124 pr_debug("stl_putchar(tty=%p,ch=%x)\n", tty, ch);
1128 portp = tty->driver_data;
1131 if (portp->tx.buf == NULL)
1134 head = portp->tx.head;
1135 tail = portp->tx.tail;
1137 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
1142 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
1143 head = portp->tx.buf;
1145 portp->tx.head = head;
1148 /*****************************************************************************/
1151 * If there are any characters in the buffer then make sure that TX
1152 * interrupts are on and get'em out. Normally used after the putchar
1153 * routine has been called.
1156 static void stl_flushchars(struct tty_struct *tty)
1158 struct stlport *portp;
1160 pr_debug("stl_flushchars(tty=%p)\n", tty);
1164 portp = tty->driver_data;
1167 if (portp->tx.buf == NULL)
1170 stl_startrxtx(portp, -1, 1);
1173 /*****************************************************************************/
1175 static int stl_writeroom(struct tty_struct *tty)
1177 struct stlport *portp;
1180 pr_debug("stl_writeroom(tty=%p)\n", tty);
1184 portp = tty->driver_data;
1187 if (portp->tx.buf == NULL)
1190 head = portp->tx.head;
1191 tail = portp->tx.tail;
1192 return ((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
1195 /*****************************************************************************/
1198 * Return number of chars in the TX buffer. Normally we would just
1199 * calculate the number of chars in the buffer and return that, but if
1200 * the buffer is empty and TX interrupts are still on then we return
1201 * that the buffer still has 1 char in it. This way whoever called us
1202 * will not think that ALL chars have drained - since the UART still
1203 * must have some chars in it (we are busy after all).
1206 static int stl_charsinbuffer(struct tty_struct *tty)
1208 struct stlport *portp;
1212 pr_debug("stl_charsinbuffer(tty=%p)\n", tty);
1216 portp = tty->driver_data;
1219 if (portp->tx.buf == NULL)
1222 head = portp->tx.head;
1223 tail = portp->tx.tail;
1224 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1225 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1230 /*****************************************************************************/
1233 * Generate the serial struct info.
1236 static int stl_getserial(struct stlport *portp, struct serial_struct __user *sp)
1238 struct serial_struct sio;
1239 struct stlbrd *brdp;
1241 pr_debug("stl_getserial(portp=%p,sp=%p)\n", portp, sp);
1243 memset(&sio, 0, sizeof(struct serial_struct));
1244 sio.line = portp->portnr;
1245 sio.port = portp->ioaddr;
1246 sio.flags = portp->flags;
1247 sio.baud_base = portp->baud_base;
1248 sio.close_delay = portp->close_delay;
1249 sio.closing_wait = portp->closing_wait;
1250 sio.custom_divisor = portp->custom_divisor;
1252 if (portp->uartp == &stl_cd1400uart) {
1253 sio.type = PORT_CIRRUS;
1254 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1256 sio.type = PORT_UNKNOWN;
1257 sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1260 brdp = stl_brds[portp->brdnr];
1262 sio.irq = brdp->irq;
1264 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
1267 /*****************************************************************************/
1270 * Set port according to the serial struct info.
1271 * At this point we do not do any auto-configure stuff, so we will
1272 * just quietly ignore any requests to change irq, etc.
1275 static int stl_setserial(struct stlport *portp, struct serial_struct __user *sp)
1277 struct serial_struct sio;
1279 pr_debug("stl_setserial(portp=%p,sp=%p)\n", portp, sp);
1281 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1283 if (!capable(CAP_SYS_ADMIN)) {
1284 if ((sio.baud_base != portp->baud_base) ||
1285 (sio.close_delay != portp->close_delay) ||
1286 ((sio.flags & ~ASYNC_USR_MASK) !=
1287 (portp->flags & ~ASYNC_USR_MASK)))
1291 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1292 (sio.flags & ASYNC_USR_MASK);
1293 portp->baud_base = sio.baud_base;
1294 portp->close_delay = sio.close_delay;
1295 portp->closing_wait = sio.closing_wait;
1296 portp->custom_divisor = sio.custom_divisor;
1297 stl_setport(portp, portp->tty->termios);
1301 /*****************************************************************************/
1303 static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1305 struct stlport *portp;
1309 portp = tty->driver_data;
1312 if (tty->flags & (1 << TTY_IO_ERROR))
1315 return stl_getsignals(portp);
1318 static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1319 unsigned int set, unsigned int clear)
1321 struct stlport *portp;
1322 int rts = -1, dtr = -1;
1326 portp = tty->driver_data;
1329 if (tty->flags & (1 << TTY_IO_ERROR))
1332 if (set & TIOCM_RTS)
1334 if (set & TIOCM_DTR)
1336 if (clear & TIOCM_RTS)
1338 if (clear & TIOCM_DTR)
1341 stl_setsignals(portp, dtr, rts);
1345 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1347 struct stlport *portp;
1350 void __user *argp = (void __user *)arg;
1352 pr_debug("stl_ioctl(tty=%p,file=%p,cmd=%x,arg=%lx)\n", tty, file, cmd,
1357 portp = tty->driver_data;
1361 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1362 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1363 if (tty->flags & (1 << TTY_IO_ERROR))
1371 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1372 (unsigned __user *) argp);
1375 if (get_user(ival, (unsigned int __user *) arg))
1377 tty->termios->c_cflag =
1378 (tty->termios->c_cflag & ~CLOCAL) |
1379 (ival ? CLOCAL : 0);
1382 rc = stl_getserial(portp, argp);
1385 rc = stl_setserial(portp, argp);
1387 case COM_GETPORTSTATS:
1388 rc = stl_getportstats(portp, argp);
1390 case COM_CLRPORTSTATS:
1391 rc = stl_clrportstats(portp, argp);
1397 case TIOCSERGSTRUCT:
1398 case TIOCSERGETMULTI:
1399 case TIOCSERSETMULTI:
1408 /*****************************************************************************/
1411 * Start the transmitter again. Just turn TX interrupts back on.
1414 static void stl_start(struct tty_struct *tty)
1416 struct stlport *portp;
1418 pr_debug("stl_start(tty=%p)\n", tty);
1422 portp = tty->driver_data;
1425 stl_startrxtx(portp, -1, 1);
1428 /*****************************************************************************/
1430 static void stl_settermios(struct tty_struct *tty, struct termios *old)
1432 struct stlport *portp;
1433 struct termios *tiosp;
1435 pr_debug("stl_settermios(tty=%p,old=%p)\n", tty, old);
1439 portp = tty->driver_data;
1443 tiosp = tty->termios;
1444 if ((tiosp->c_cflag == old->c_cflag) &&
1445 (tiosp->c_iflag == old->c_iflag))
1448 stl_setport(portp, tiosp);
1449 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1451 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1452 tty->hw_stopped = 0;
1455 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1456 wake_up_interruptible(&portp->open_wait);
1459 /*****************************************************************************/
1462 * Attempt to flow control who ever is sending us data. Based on termios
1463 * settings use software or/and hardware flow control.
1466 static void stl_throttle(struct tty_struct *tty)
1468 struct stlport *portp;
1470 pr_debug("stl_throttle(tty=%p)\n", tty);
1474 portp = tty->driver_data;
1477 stl_flowctrl(portp, 0);
1480 /*****************************************************************************/
1483 * Unflow control the device sending us data...
1486 static void stl_unthrottle(struct tty_struct *tty)
1488 struct stlport *portp;
1490 pr_debug("stl_unthrottle(tty=%p)\n", tty);
1494 portp = tty->driver_data;
1497 stl_flowctrl(portp, 1);
1500 /*****************************************************************************/
1503 * Stop the transmitter. Basically to do this we will just turn TX
1507 static void stl_stop(struct tty_struct *tty)
1509 struct stlport *portp;
1511 pr_debug("stl_stop(tty=%p)\n", tty);
1515 portp = tty->driver_data;
1518 stl_startrxtx(portp, -1, 0);
1521 /*****************************************************************************/
1524 * Hangup this port. This is pretty much like closing the port, only
1525 * a little more brutal. No waiting for data to drain. Shutdown the
1526 * port and maybe drop signals.
1529 static void stl_hangup(struct tty_struct *tty)
1531 struct stlport *portp;
1533 pr_debug("stl_hangup(tty=%p)\n", tty);
1537 portp = tty->driver_data;
1541 portp->flags &= ~ASYNC_INITIALIZED;
1542 stl_disableintrs(portp);
1543 if (tty->termios->c_cflag & HUPCL)
1544 stl_setsignals(portp, 0, 0);
1545 stl_enablerxtx(portp, 0, 0);
1546 stl_flushbuffer(tty);
1548 set_bit(TTY_IO_ERROR, &tty->flags);
1549 if (portp->tx.buf != NULL) {
1550 kfree(portp->tx.buf);
1551 portp->tx.buf = NULL;
1552 portp->tx.head = NULL;
1553 portp->tx.tail = NULL;
1556 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1557 portp->refcount = 0;
1558 wake_up_interruptible(&portp->open_wait);
1561 /*****************************************************************************/
1563 static void stl_breakctl(struct tty_struct *tty, int state)
1565 struct stlport *portp;
1567 pr_debug("stl_breakctl(tty=%p,state=%d)\n", tty, state);
1571 portp = tty->driver_data;
1575 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1578 /*****************************************************************************/
1580 static void stl_sendxchar(struct tty_struct *tty, char ch)
1582 struct stlport *portp;
1584 pr_debug("stl_sendxchar(tty=%p,ch=%x)\n", tty, ch);
1588 portp = tty->driver_data;
1592 if (ch == STOP_CHAR(tty))
1593 stl_sendflow(portp, 0);
1594 else if (ch == START_CHAR(tty))
1595 stl_sendflow(portp, 1);
1597 stl_putchar(tty, ch);
1600 /*****************************************************************************/
1605 * Format info for a specified port. The line is deliberately limited
1606 * to 80 characters. (If it is too long it will be truncated, if too
1607 * short then padded with spaces).
1610 static int stl_portinfo(struct stlport *portp, int portnr, char *pos)
1616 sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
1617 portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
1618 (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
1620 if (portp->stats.rxframing)
1621 sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
1622 if (portp->stats.rxparity)
1623 sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
1624 if (portp->stats.rxbreaks)
1625 sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
1626 if (portp->stats.rxoverrun)
1627 sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
1629 sigs = stl_getsignals(portp);
1630 cnt = sprintf(sp, "%s%s%s%s%s ",
1631 (sigs & TIOCM_RTS) ? "|RTS" : "",
1632 (sigs & TIOCM_CTS) ? "|CTS" : "",
1633 (sigs & TIOCM_DTR) ? "|DTR" : "",
1634 (sigs & TIOCM_CD) ? "|DCD" : "",
1635 (sigs & TIOCM_DSR) ? "|DSR" : "");
1639 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
1642 pos[(MAXLINE - 2)] = '+';
1643 pos[(MAXLINE - 1)] = '\n';
1648 /*****************************************************************************/
1651 * Port info, read from the /proc file system.
1654 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
1656 struct stlbrd *brdp;
1657 struct stlpanel *panelp;
1658 struct stlport *portp;
1659 int brdnr, panelnr, portnr, totalport;
1663 pr_debug("stl_readproc(page=%p,start=%p,off=%lx,count=%d,eof=%p,"
1664 "data=%p\n", page, start, off, count, eof, data);
1671 pos += sprintf(pos, "%s: version %s", stl_drvtitle,
1673 while (pos < (page + MAXLINE - 1))
1680 * We scan through for each board, panel and port. The offset is
1681 * calculated on the fly, and irrelevant ports are skipped.
1683 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1684 brdp = stl_brds[brdnr];
1687 if (brdp->state == 0)
1690 maxoff = curoff + (brdp->nrports * MAXLINE);
1691 if (off >= maxoff) {
1696 totalport = brdnr * STL_MAXPORTS;
1697 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1698 panelp = brdp->panels[panelnr];
1702 maxoff = curoff + (panelp->nrports * MAXLINE);
1703 if (off >= maxoff) {
1705 totalport += panelp->nrports;
1709 for (portnr = 0; (portnr < panelp->nrports); portnr++,
1711 portp = panelp->ports[portnr];
1714 if (off >= (curoff += MAXLINE))
1716 if ((pos - page + MAXLINE) > count)
1718 pos += stl_portinfo(portp, totalport, pos);
1727 return (pos - page);
1730 /*****************************************************************************/
1733 * All board interrupts are vectored through here first. This code then
1734 * calls off to the approrpriate board interrupt handlers.
1737 static irqreturn_t stl_intr(int irq, void *dev_id)
1739 struct stlbrd *brdp = dev_id;
1741 pr_debug("stl_intr(brdp=%p,irq=%d)\n", brdp, irq);
1743 return IRQ_RETVAL((* brdp->isr)(brdp));
1746 /*****************************************************************************/
1749 * Interrupt service routine for EasyIO board types.
1752 static int stl_eiointr(struct stlbrd *brdp)
1754 struct stlpanel *panelp;
1755 unsigned int iobase;
1758 spin_lock(&brd_lock);
1759 panelp = brdp->panels[0];
1760 iobase = panelp->iobase;
1761 while (inb(brdp->iostatus) & EIO_INTRPEND) {
1763 (* panelp->isr)(panelp, iobase);
1765 spin_unlock(&brd_lock);
1769 /*****************************************************************************/
1772 * Interrupt service routine for ECH-AT board types.
1775 static int stl_echatintr(struct stlbrd *brdp)
1777 struct stlpanel *panelp;
1778 unsigned int ioaddr;
1782 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
1784 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1786 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1787 ioaddr = brdp->bnkstataddr[bnknr];
1788 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1789 panelp = brdp->bnk2panel[bnknr];
1790 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1795 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
1800 /*****************************************************************************/
1803 * Interrupt service routine for ECH-MCA board types.
1806 static int stl_echmcaintr(struct stlbrd *brdp)
1808 struct stlpanel *panelp;
1809 unsigned int ioaddr;
1813 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1815 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1816 ioaddr = brdp->bnkstataddr[bnknr];
1817 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1818 panelp = brdp->bnk2panel[bnknr];
1819 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1826 /*****************************************************************************/
1829 * Interrupt service routine for ECH-PCI board types.
1832 static int stl_echpciintr(struct stlbrd *brdp)
1834 struct stlpanel *panelp;
1835 unsigned int ioaddr;
1841 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1842 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
1843 ioaddr = brdp->bnkstataddr[bnknr];
1844 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1845 panelp = brdp->bnk2panel[bnknr];
1846 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1857 /*****************************************************************************/
1860 * Interrupt service routine for ECH-8/64-PCI board types.
1863 static int stl_echpci64intr(struct stlbrd *brdp)
1865 struct stlpanel *panelp;
1866 unsigned int ioaddr;
1870 while (inb(brdp->ioctrl) & 0x1) {
1872 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1873 ioaddr = brdp->bnkstataddr[bnknr];
1874 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1875 panelp = brdp->bnk2panel[bnknr];
1876 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1884 /*****************************************************************************/
1887 * Service an off-level request for some channel.
1889 static void stl_offintr(struct work_struct *work)
1891 struct stlport *portp = container_of(work, struct stlport, tqueue);
1892 struct tty_struct *tty;
1893 unsigned int oldsigs;
1895 pr_debug("stl_offintr(portp=%p)\n", portp);
1905 if (test_bit(ASYI_TXLOW, &portp->istate)) {
1908 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
1909 clear_bit(ASYI_DCDCHANGE, &portp->istate);
1910 oldsigs = portp->sigs;
1911 portp->sigs = stl_getsignals(portp);
1912 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
1913 wake_up_interruptible(&portp->open_wait);
1914 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
1915 if (portp->flags & ASYNC_CHECK_CD)
1916 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
1922 /*****************************************************************************/
1925 * Initialize all the ports on a panel.
1928 static int __init stl_initports(struct stlbrd *brdp, struct stlpanel *panelp)
1930 struct stlport *portp;
1933 pr_debug("stl_initports(brdp=%p,panelp=%p)\n", brdp, panelp);
1935 chipmask = stl_panelinit(brdp, panelp);
1938 * All UART's are initialized (if found!). Now go through and setup
1939 * each ports data structures.
1941 for (i = 0; (i < panelp->nrports); i++) {
1942 portp = kzalloc(sizeof(struct stlport), GFP_KERNEL);
1944 printk("STALLION: failed to allocate memory "
1945 "(size=%Zd)\n", sizeof(struct stlport));
1949 portp->magic = STL_PORTMAGIC;
1951 portp->brdnr = panelp->brdnr;
1952 portp->panelnr = panelp->panelnr;
1953 portp->uartp = panelp->uartp;
1954 portp->clk = brdp->clk;
1955 portp->baud_base = STL_BAUDBASE;
1956 portp->close_delay = STL_CLOSEDELAY;
1957 portp->closing_wait = 30 * HZ;
1958 INIT_WORK(&portp->tqueue, stl_offintr);
1959 init_waitqueue_head(&portp->open_wait);
1960 init_waitqueue_head(&portp->close_wait);
1961 portp->stats.brd = portp->brdnr;
1962 portp->stats.panel = portp->panelnr;
1963 portp->stats.port = portp->portnr;
1964 panelp->ports[i] = portp;
1965 stl_portinit(brdp, panelp, portp);
1971 /*****************************************************************************/
1974 * Try to find and initialize an EasyIO board.
1977 static int __init stl_initeio(struct stlbrd *brdp)
1979 struct stlpanel *panelp;
1980 unsigned int status;
1984 pr_debug("stl_initeio(brdp=%p)\n", brdp);
1986 brdp->ioctrl = brdp->ioaddr1 + 1;
1987 brdp->iostatus = brdp->ioaddr1 + 2;
1989 status = inb(brdp->iostatus);
1990 if ((status & EIO_IDBITMASK) == EIO_MK3)
1994 * Handle board specific stuff now. The real difference is PCI
1997 if (brdp->brdtype == BRD_EASYIOPCI) {
1998 brdp->iosize1 = 0x80;
1999 brdp->iosize2 = 0x80;
2000 name = "serial(EIO-PCI)";
2001 outb(0x41, (brdp->ioaddr2 + 0x4c));
2004 name = "serial(EIO)";
2005 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2006 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2007 printk("STALLION: invalid irq=%d for brd=%d\n",
2008 brdp->irq, brdp->brdnr);
2011 outb((stl_vecmap[brdp->irq] | EIO_0WS |
2012 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
2016 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2017 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2018 "%x conflicts with another device\n", brdp->brdnr,
2023 if (brdp->iosize2 > 0)
2024 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2025 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2026 "address %x conflicts with another device\n",
2027 brdp->brdnr, brdp->ioaddr2);
2028 printk(KERN_WARNING "STALLION: Warning, also "
2029 "releasing board %d I/O address %x \n",
2030 brdp->brdnr, brdp->ioaddr1);
2031 release_region(brdp->ioaddr1, brdp->iosize1);
2036 * Everything looks OK, so let's go ahead and probe for the hardware.
2038 brdp->clk = CD1400_CLK;
2039 brdp->isr = stl_eiointr;
2041 switch (status & EIO_IDBITMASK) {
2043 brdp->clk = CD1400_CLK8M;
2053 switch (status & EIO_BRDMASK) {
2072 * We have verified that the board is actually present, so now we
2073 * can complete the setup.
2076 panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
2078 printk(KERN_WARNING "STALLION: failed to allocate memory "
2079 "(size=%Zd)\n", sizeof(struct stlpanel));
2083 panelp->magic = STL_PANELMAGIC;
2084 panelp->brdnr = brdp->brdnr;
2085 panelp->panelnr = 0;
2086 panelp->nrports = brdp->nrports;
2087 panelp->iobase = brdp->ioaddr1;
2088 panelp->hwid = status;
2089 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2090 panelp->uartp = &stl_sc26198uart;
2091 panelp->isr = stl_sc26198intr;
2093 panelp->uartp = &stl_cd1400uart;
2094 panelp->isr = stl_cd1400eiointr;
2097 brdp->panels[0] = panelp;
2099 brdp->state |= BRD_FOUND;
2100 brdp->hwid = status;
2101 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
2102 printk("STALLION: failed to register interrupt "
2103 "routine for %s irq=%d\n", name, brdp->irq);
2111 /*****************************************************************************/
2114 * Try to find an ECH board and initialize it. This code is capable of
2115 * dealing with all types of ECH board.
2118 static int __init stl_initech(struct stlbrd *brdp)
2120 struct stlpanel *panelp;
2121 unsigned int status, nxtid, ioaddr, conflict;
2122 int panelnr, banknr, i;
2125 pr_debug("stl_initech(brdp=%p)\n", brdp);
2131 * Set up the initial board register contents for boards. This varies a
2132 * bit between the different board types. So we need to handle each
2133 * separately. Also do a check that the supplied IRQ is good.
2135 switch (brdp->brdtype) {
2138 brdp->isr = stl_echatintr;
2139 brdp->ioctrl = brdp->ioaddr1 + 1;
2140 brdp->iostatus = brdp->ioaddr1 + 1;
2141 status = inb(brdp->iostatus);
2142 if ((status & ECH_IDBITMASK) != ECH_ID)
2144 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2145 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2146 printk("STALLION: invalid irq=%d for brd=%d\n",
2147 brdp->irq, brdp->brdnr);
2150 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2151 status |= (stl_vecmap[brdp->irq] << 1);
2152 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2153 brdp->ioctrlval = ECH_INTENABLE |
2154 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2155 for (i = 0; (i < 10); i++)
2156 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2159 name = "serial(EC8/32)";
2160 outb(status, brdp->ioaddr1);
2164 brdp->isr = stl_echmcaintr;
2165 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2166 brdp->iostatus = brdp->ioctrl;
2167 status = inb(brdp->iostatus);
2168 if ((status & ECH_IDBITMASK) != ECH_ID)
2170 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2171 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2172 printk("STALLION: invalid irq=%d for brd=%d\n",
2173 brdp->irq, brdp->brdnr);
2176 outb(ECHMC_BRDRESET, brdp->ioctrl);
2177 outb(ECHMC_INTENABLE, brdp->ioctrl);
2179 name = "serial(EC8/32-MC)";
2183 brdp->isr = stl_echpciintr;
2184 brdp->ioctrl = brdp->ioaddr1 + 2;
2187 name = "serial(EC8/32-PCI)";
2191 brdp->isr = stl_echpci64intr;
2192 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2193 outb(0x43, (brdp->ioaddr1 + 0x4c));
2194 brdp->iosize1 = 0x80;
2195 brdp->iosize2 = 0x80;
2196 name = "serial(EC8/64-PCI)";
2200 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
2206 * Check boards for possible IO address conflicts and return fail status
2207 * if an IO conflict found.
2209 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2210 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2211 "%x conflicts with another device\n", brdp->brdnr,
2216 if (brdp->iosize2 > 0)
2217 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2218 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2219 "address %x conflicts with another device\n",
2220 brdp->brdnr, brdp->ioaddr2);
2221 printk(KERN_WARNING "STALLION: Warning, also "
2222 "releasing board %d I/O address %x \n",
2223 brdp->brdnr, brdp->ioaddr1);
2224 release_region(brdp->ioaddr1, brdp->iosize1);
2229 * Scan through the secondary io address space looking for panels.
2230 * As we find'em allocate and initialize panel structures for each.
2232 brdp->clk = CD1400_CLK;
2233 brdp->hwid = status;
2235 ioaddr = brdp->ioaddr2;
2240 for (i = 0; (i < STL_MAXPANELS); i++) {
2241 if (brdp->brdtype == BRD_ECHPCI) {
2242 outb(nxtid, brdp->ioctrl);
2243 ioaddr = brdp->ioaddr2;
2245 status = inb(ioaddr + ECH_PNLSTATUS);
2246 if ((status & ECH_PNLIDMASK) != nxtid)
2248 panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
2250 printk("STALLION: failed to allocate memory "
2251 "(size=%Zd)\n", sizeof(struct stlpanel));
2254 panelp->magic = STL_PANELMAGIC;
2255 panelp->brdnr = brdp->brdnr;
2256 panelp->panelnr = panelnr;
2257 panelp->iobase = ioaddr;
2258 panelp->pagenr = nxtid;
2259 panelp->hwid = status;
2260 brdp->bnk2panel[banknr] = panelp;
2261 brdp->bnkpageaddr[banknr] = nxtid;
2262 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2264 if (status & ECH_PNLXPID) {
2265 panelp->uartp = &stl_sc26198uart;
2266 panelp->isr = stl_sc26198intr;
2267 if (status & ECH_PNL16PORT) {
2268 panelp->nrports = 16;
2269 brdp->bnk2panel[banknr] = panelp;
2270 brdp->bnkpageaddr[banknr] = nxtid;
2271 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2274 panelp->nrports = 8;
2277 panelp->uartp = &stl_cd1400uart;
2278 panelp->isr = stl_cd1400echintr;
2279 if (status & ECH_PNL16PORT) {
2280 panelp->nrports = 16;
2281 panelp->ackmask = 0x80;
2282 if (brdp->brdtype != BRD_ECHPCI)
2283 ioaddr += EREG_BANKSIZE;
2284 brdp->bnk2panel[banknr] = panelp;
2285 brdp->bnkpageaddr[banknr] = ++nxtid;
2286 brdp->bnkstataddr[banknr++] = ioaddr +
2289 panelp->nrports = 8;
2290 panelp->ackmask = 0xc0;
2295 ioaddr += EREG_BANKSIZE;
2296 brdp->nrports += panelp->nrports;
2297 brdp->panels[panelnr++] = panelp;
2298 if ((brdp->brdtype != BRD_ECHPCI) &&
2299 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
2303 brdp->nrpanels = panelnr;
2304 brdp->nrbnks = banknr;
2305 if (brdp->brdtype == BRD_ECH)
2306 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2308 brdp->state |= BRD_FOUND;
2309 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
2310 printk("STALLION: failed to register interrupt "
2311 "routine for %s irq=%d\n", name, brdp->irq);
2320 /*****************************************************************************/
2323 * Initialize and configure the specified board.
2324 * Scan through all the boards in the configuration and see what we
2325 * can find. Handle EIO and the ECH boards a little differently here
2326 * since the initial search and setup is very different.
2329 static int __init stl_brdinit(struct stlbrd *brdp)
2333 pr_debug("stl_brdinit(brdp=%p)\n", brdp);
2335 switch (brdp->brdtype) {
2347 printk("STALLION: board=%d is unknown board type=%d\n",
2348 brdp->brdnr, brdp->brdtype);
2352 stl_brds[brdp->brdnr] = brdp;
2353 if ((brdp->state & BRD_FOUND) == 0) {
2354 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2355 stl_brdnames[brdp->brdtype], brdp->brdnr,
2356 brdp->ioaddr1, brdp->irq);
2360 for (i = 0; (i < STL_MAXPANELS); i++)
2361 if (brdp->panels[i] != NULL)
2362 stl_initports(brdp, brdp->panels[i]);
2364 printk("STALLION: %s found, board=%d io=%x irq=%d "
2365 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2366 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2371 /*****************************************************************************/
2374 * Find the next available board number that is free.
2377 static int __init stl_getbrdnr(void)
2381 for (i = 0; (i < STL_MAXBRDS); i++) {
2382 if (stl_brds[i] == NULL) {
2383 if (i >= stl_nrbrds)
2391 /*****************************************************************************/
2396 * We have a Stallion board. Allocate a board structure and
2397 * initialize it. Read its IO and IRQ resources from PCI
2398 * configuration space.
2401 static int __init stl_initpcibrd(int brdtype, struct pci_dev *devp)
2403 struct stlbrd *brdp;
2405 pr_debug("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
2406 devp->bus->number, devp->devfn);
2408 if (pci_enable_device(devp))
2410 if ((brdp = stl_allocbrd()) == NULL)
2412 if ((brdp->brdnr = stl_getbrdnr()) < 0) {
2413 printk("STALLION: too many boards found, "
2414 "maximum supported %d\n", STL_MAXBRDS);
2417 brdp->brdtype = brdtype;
2420 * Different Stallion boards use the BAR registers in different ways,
2421 * so set up io addresses based on board type.
2423 pr_debug("%s(%d): BAR[]=%Lx,%Lx,%Lx,%Lx IRQ=%x\n", __FILE__, __LINE__,
2424 pci_resource_start(devp, 0), pci_resource_start(devp, 1),
2425 pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
2428 * We have all resources from the board, so let's setup the actual
2429 * board structure now.
2433 brdp->ioaddr2 = pci_resource_start(devp, 0);
2434 brdp->ioaddr1 = pci_resource_start(devp, 1);
2437 brdp->ioaddr2 = pci_resource_start(devp, 2);
2438 brdp->ioaddr1 = pci_resource_start(devp, 1);
2441 brdp->ioaddr1 = pci_resource_start(devp, 2);
2442 brdp->ioaddr2 = pci_resource_start(devp, 1);
2445 printk("STALLION: unknown PCI board type=%d\n", brdtype);
2449 brdp->irq = devp->irq;
2455 /*****************************************************************************/
2458 * Find all Stallion PCI boards that might be installed. Initialize each
2459 * one as it is found.
2463 static int __init stl_findpcibrds(void)
2465 struct pci_dev *dev = NULL;
2468 pr_debug("stl_findpcibrds()\n");
2470 for (i = 0; (i < stl_nrpcibrds); i++)
2471 while ((dev = pci_find_device(stl_pcibrds[i].vendid,
2472 stl_pcibrds[i].devid, dev))) {
2475 * Found a device on the PCI bus that has our vendor and
2476 * device ID. Need to check now that it is really us.
2478 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2481 rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
2491 /*****************************************************************************/
2494 * Scan through all the boards in the configuration and see what we
2495 * can find. Handle EIO and the ECH boards a little differently here
2496 * since the initial search and setup is too different.
2499 static int __init stl_initbrds(void)
2501 struct stlbrd *brdp;
2502 struct stlconf *confp;
2505 pr_debug("stl_initbrds()\n");
2507 if (stl_nrbrds > STL_MAXBRDS) {
2508 printk("STALLION: too many boards in configuration table, "
2509 "truncating to %d\n", STL_MAXBRDS);
2510 stl_nrbrds = STL_MAXBRDS;
2514 * Firstly scan the list of static boards configured. Allocate
2515 * resources and initialize the boards as found.
2517 for (i = 0; (i < stl_nrbrds); i++) {
2518 confp = &stl_brdconf[i];
2519 stl_parsebrd(confp, stl_brdsp[i]);
2520 if ((brdp = stl_allocbrd()) == NULL)
2523 brdp->brdtype = confp->brdtype;
2524 brdp->ioaddr1 = confp->ioaddr1;
2525 brdp->ioaddr2 = confp->ioaddr2;
2526 brdp->irq = confp->irq;
2527 brdp->irqtype = confp->irqtype;
2532 * Find any dynamically supported boards. That is via module load
2533 * line options or auto-detected on the PCI bus.
2543 /*****************************************************************************/
2546 * Return the board stats structure to user app.
2549 static int stl_getbrdstats(combrd_t __user *bp)
2551 struct stlbrd *brdp;
2552 struct stlpanel *panelp;
2555 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2557 if (stl_brdstats.brd >= STL_MAXBRDS)
2559 brdp = stl_brds[stl_brdstats.brd];
2563 memset(&stl_brdstats, 0, sizeof(combrd_t));
2564 stl_brdstats.brd = brdp->brdnr;
2565 stl_brdstats.type = brdp->brdtype;
2566 stl_brdstats.hwid = brdp->hwid;
2567 stl_brdstats.state = brdp->state;
2568 stl_brdstats.ioaddr = brdp->ioaddr1;
2569 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2570 stl_brdstats.irq = brdp->irq;
2571 stl_brdstats.nrpanels = brdp->nrpanels;
2572 stl_brdstats.nrports = brdp->nrports;
2573 for (i = 0; (i < brdp->nrpanels); i++) {
2574 panelp = brdp->panels[i];
2575 stl_brdstats.panels[i].panel = i;
2576 stl_brdstats.panels[i].hwid = panelp->hwid;
2577 stl_brdstats.panels[i].nrports = panelp->nrports;
2580 return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
2583 /*****************************************************************************/
2586 * Resolve the referenced port number into a port struct pointer.
2589 static struct stlport *stl_getport(int brdnr, int panelnr, int portnr)
2591 struct stlbrd *brdp;
2592 struct stlpanel *panelp;
2594 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2596 brdp = stl_brds[brdnr];
2599 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2601 panelp = brdp->panels[panelnr];
2604 if ((portnr < 0) || (portnr >= panelp->nrports))
2606 return(panelp->ports[portnr]);
2609 /*****************************************************************************/
2612 * Return the port stats structure to user app. A NULL port struct
2613 * pointer passed in means that we need to find out from the app
2614 * what port to get stats for (used through board control device).
2617 static int stl_getportstats(struct stlport *portp, comstats_t __user *cp)
2619 unsigned char *head, *tail;
2620 unsigned long flags;
2623 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2625 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2631 portp->stats.state = portp->istate;
2632 portp->stats.flags = portp->flags;
2633 portp->stats.hwid = portp->hwid;
2635 portp->stats.ttystate = 0;
2636 portp->stats.cflags = 0;
2637 portp->stats.iflags = 0;
2638 portp->stats.oflags = 0;
2639 portp->stats.lflags = 0;
2640 portp->stats.rxbuffered = 0;
2642 spin_lock_irqsave(&stallion_lock, flags);
2643 if (portp->tty != NULL) {
2644 if (portp->tty->driver_data == portp) {
2645 portp->stats.ttystate = portp->tty->flags;
2646 /* No longer available as a statistic */
2647 portp->stats.rxbuffered = 1; /*portp->tty->flip.count; */
2648 if (portp->tty->termios != NULL) {
2649 portp->stats.cflags = portp->tty->termios->c_cflag;
2650 portp->stats.iflags = portp->tty->termios->c_iflag;
2651 portp->stats.oflags = portp->tty->termios->c_oflag;
2652 portp->stats.lflags = portp->tty->termios->c_lflag;
2656 spin_unlock_irqrestore(&stallion_lock, flags);
2658 head = portp->tx.head;
2659 tail = portp->tx.tail;
2660 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2661 (STL_TXBUFSIZE - (tail - head)));
2663 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2665 return copy_to_user(cp, &portp->stats,
2666 sizeof(comstats_t)) ? -EFAULT : 0;
2669 /*****************************************************************************/
2672 * Clear the port stats structure. We also return it zeroed out...
2675 static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp)
2678 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2680 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2686 memset(&portp->stats, 0, sizeof(comstats_t));
2687 portp->stats.brd = portp->brdnr;
2688 portp->stats.panel = portp->panelnr;
2689 portp->stats.port = portp->portnr;
2690 return copy_to_user(cp, &portp->stats,
2691 sizeof(comstats_t)) ? -EFAULT : 0;
2694 /*****************************************************************************/
2697 * Return the entire driver ports structure to a user app.
2700 static int stl_getportstruct(struct stlport __user *arg)
2702 struct stlport *portp;
2704 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
2706 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
2707 stl_dummyport.portnr);
2710 return copy_to_user(arg, portp, sizeof(struct stlport)) ? -EFAULT : 0;
2713 /*****************************************************************************/
2716 * Return the entire driver board structure to a user app.
2719 static int stl_getbrdstruct(struct stlbrd __user *arg)
2721 struct stlbrd *brdp;
2723 if (copy_from_user(&stl_dummybrd, arg, sizeof(struct stlbrd)))
2725 if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
2727 brdp = stl_brds[stl_dummybrd.brdnr];
2730 return copy_to_user(arg, brdp, sizeof(struct stlbrd)) ? -EFAULT : 0;
2733 /*****************************************************************************/
2736 * The "staliomem" device is also required to do some special operations
2737 * on the board and/or ports. In this driver it is mostly used for stats
2741 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
2744 void __user *argp = (void __user *)arg;
2746 pr_debug("stl_memioctl(ip=%p,fp=%p,cmd=%x,arg=%lx)\n", ip, fp, cmd,arg);
2749 if (brdnr >= STL_MAXBRDS)
2754 case COM_GETPORTSTATS:
2755 rc = stl_getportstats(NULL, argp);
2757 case COM_CLRPORTSTATS:
2758 rc = stl_clrportstats(NULL, argp);
2760 case COM_GETBRDSTATS:
2761 rc = stl_getbrdstats(argp);
2764 rc = stl_getportstruct(argp);
2767 rc = stl_getbrdstruct(argp);
2777 static const struct tty_operations stl_ops = {
2781 .put_char = stl_putchar,
2782 .flush_chars = stl_flushchars,
2783 .write_room = stl_writeroom,
2784 .chars_in_buffer = stl_charsinbuffer,
2786 .set_termios = stl_settermios,
2787 .throttle = stl_throttle,
2788 .unthrottle = stl_unthrottle,
2791 .hangup = stl_hangup,
2792 .flush_buffer = stl_flushbuffer,
2793 .break_ctl = stl_breakctl,
2794 .wait_until_sent = stl_waituntilsent,
2795 .send_xchar = stl_sendxchar,
2796 .read_proc = stl_readproc,
2797 .tiocmget = stl_tiocmget,
2798 .tiocmset = stl_tiocmset,
2801 /*****************************************************************************/
2802 /* CD1400 HARDWARE FUNCTIONS */
2803 /*****************************************************************************/
2806 * These functions get/set/update the registers of the cd1400 UARTs.
2807 * Access to the cd1400 registers is via an address/data io port pair.
2808 * (Maybe should make this inline...)
2811 static int stl_cd1400getreg(struct stlport *portp, int regnr)
2813 outb((regnr + portp->uartaddr), portp->ioaddr);
2814 return inb(portp->ioaddr + EREG_DATA);
2817 static void stl_cd1400setreg(struct stlport *portp, int regnr, int value)
2819 outb((regnr + portp->uartaddr), portp->ioaddr);
2820 outb(value, portp->ioaddr + EREG_DATA);
2823 static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value)
2825 outb((regnr + portp->uartaddr), portp->ioaddr);
2826 if (inb(portp->ioaddr + EREG_DATA) != value) {
2827 outb(value, portp->ioaddr + EREG_DATA);
2833 /*****************************************************************************/
2836 * Inbitialize the UARTs in a panel. We don't care what sort of board
2837 * these ports are on - since the port io registers are almost
2838 * identical when dealing with ports.
2841 static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
2845 int nrchips, uartaddr, ioaddr;
2846 unsigned long flags;
2848 pr_debug("stl_panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
2850 spin_lock_irqsave(&brd_lock, flags);
2851 BRDENABLE(panelp->brdnr, panelp->pagenr);
2854 * Check that each chip is present and started up OK.
2857 nrchips = panelp->nrports / CD1400_PORTS;
2858 for (i = 0; (i < nrchips); i++) {
2859 if (brdp->brdtype == BRD_ECHPCI) {
2860 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
2861 ioaddr = panelp->iobase;
2863 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
2865 uartaddr = (i & 0x01) ? 0x080 : 0;
2866 outb((GFRCR + uartaddr), ioaddr);
2867 outb(0, (ioaddr + EREG_DATA));
2868 outb((CCR + uartaddr), ioaddr);
2869 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
2870 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
2871 outb((GFRCR + uartaddr), ioaddr);
2872 for (j = 0; (j < CCR_MAXWAIT); j++) {
2873 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
2876 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
2877 printk("STALLION: cd1400 not responding, "
2878 "brd=%d panel=%d chip=%d\n",
2879 panelp->brdnr, panelp->panelnr, i);
2882 chipmask |= (0x1 << i);
2883 outb((PPR + uartaddr), ioaddr);
2884 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
2887 BRDDISABLE(panelp->brdnr);
2888 spin_unlock_irqrestore(&brd_lock, flags);
2892 /*****************************************************************************/
2895 * Initialize hardware specific port registers.
2898 static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
2900 unsigned long flags;
2901 pr_debug("stl_cd1400portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
2904 if ((brdp == NULL) || (panelp == NULL) ||
2908 spin_lock_irqsave(&brd_lock, flags);
2909 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
2910 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
2911 portp->uartaddr = (portp->portnr & 0x04) << 5;
2912 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
2914 BRDENABLE(portp->brdnr, portp->pagenr);
2915 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2916 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
2917 portp->hwid = stl_cd1400getreg(portp, GFRCR);
2918 BRDDISABLE(portp->brdnr);
2919 spin_unlock_irqrestore(&brd_lock, flags);
2922 /*****************************************************************************/
2925 * Wait for the command register to be ready. We will poll this,
2926 * since it won't usually take too long to be ready.
2929 static void stl_cd1400ccrwait(struct stlport *portp)
2933 for (i = 0; (i < CCR_MAXWAIT); i++) {
2934 if (stl_cd1400getreg(portp, CCR) == 0) {
2939 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
2940 portp->portnr, portp->panelnr, portp->brdnr);
2943 /*****************************************************************************/
2946 * Set up the cd1400 registers for a port based on the termios port
2950 static void stl_cd1400setport(struct stlport *portp, struct termios *tiosp)
2952 struct stlbrd *brdp;
2953 unsigned long flags;
2954 unsigned int clkdiv, baudrate;
2955 unsigned char cor1, cor2, cor3;
2956 unsigned char cor4, cor5, ccr;
2957 unsigned char srer, sreron, sreroff;
2958 unsigned char mcor1, mcor2, rtpr;
2959 unsigned char clk, div;
2975 brdp = stl_brds[portp->brdnr];
2980 * Set up the RX char ignore mask with those RX error types we
2981 * can ignore. We can get the cd1400 to help us out a little here,
2982 * it will ignore parity errors and breaks for us.
2984 portp->rxignoremsk = 0;
2985 if (tiosp->c_iflag & IGNPAR) {
2986 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
2987 cor1 |= COR1_PARIGNORE;
2989 if (tiosp->c_iflag & IGNBRK) {
2990 portp->rxignoremsk |= ST_BREAK;
2991 cor4 |= COR4_IGNBRK;
2994 portp->rxmarkmsk = ST_OVERRUN;
2995 if (tiosp->c_iflag & (INPCK | PARMRK))
2996 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
2997 if (tiosp->c_iflag & BRKINT)
2998 portp->rxmarkmsk |= ST_BREAK;
3001 * Go through the char size, parity and stop bits and set all the
3002 * option register appropriately.
3004 switch (tiosp->c_cflag & CSIZE) {
3019 if (tiosp->c_cflag & CSTOPB)
3024 if (tiosp->c_cflag & PARENB) {
3025 if (tiosp->c_cflag & PARODD)
3026 cor1 |= (COR1_PARENB | COR1_PARODD);
3028 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3030 cor1 |= COR1_PARNONE;
3034 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3035 * space for hardware flow control and the like. This should be set to
3036 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3037 * really be based on VTIME.
3039 cor3 |= FIFO_RXTHRESHOLD;
3043 * Calculate the baud rate timers. For now we will just assume that
3044 * the input and output baud are the same. Could have used a baud
3045 * table here, but this way we can generate virtually any baud rate
3048 baudrate = tiosp->c_cflag & CBAUD;
3049 if (baudrate & CBAUDEX) {
3050 baudrate &= ~CBAUDEX;
3051 if ((baudrate < 1) || (baudrate > 4))
3052 tiosp->c_cflag &= ~CBAUDEX;
3056 baudrate = stl_baudrates[baudrate];
3057 if ((tiosp->c_cflag & CBAUD) == B38400) {
3058 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3060 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3062 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3064 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3066 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3067 baudrate = (portp->baud_base / portp->custom_divisor);
3069 if (baudrate > STL_CD1400MAXBAUD)
3070 baudrate = STL_CD1400MAXBAUD;
3073 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3074 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
3078 div = (unsigned char) clkdiv;
3082 * Check what form of modem signaling is required and set it up.
3084 if ((tiosp->c_cflag & CLOCAL) == 0) {
3087 sreron |= SRER_MODEM;
3088 portp->flags |= ASYNC_CHECK_CD;
3090 portp->flags &= ~ASYNC_CHECK_CD;
3094 * Setup cd1400 enhanced modes if we can. In particular we want to
3095 * handle as much of the flow control as possible automatically. As
3096 * well as saving a few CPU cycles it will also greatly improve flow
3097 * control reliability.
3099 if (tiosp->c_iflag & IXON) {
3102 if (tiosp->c_iflag & IXANY)
3106 if (tiosp->c_cflag & CRTSCTS) {
3108 mcor1 |= FIFO_RTSTHRESHOLD;
3112 * All cd1400 register values calculated so go through and set
3116 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3117 portp->portnr, portp->panelnr, portp->brdnr);
3118 pr_debug(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3119 cor1, cor2, cor3, cor4, cor5);
3120 pr_debug(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3121 mcor1, mcor2, rtpr, sreron, sreroff);
3122 pr_debug(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3123 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3124 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3125 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3127 spin_lock_irqsave(&brd_lock, flags);
3128 BRDENABLE(portp->brdnr, portp->pagenr);
3129 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3130 srer = stl_cd1400getreg(portp, SRER);
3131 stl_cd1400setreg(portp, SRER, 0);
3132 if (stl_cd1400updatereg(portp, COR1, cor1))
3134 if (stl_cd1400updatereg(portp, COR2, cor2))
3136 if (stl_cd1400updatereg(portp, COR3, cor3))
3139 stl_cd1400ccrwait(portp);
3140 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3142 stl_cd1400setreg(portp, COR4, cor4);
3143 stl_cd1400setreg(portp, COR5, cor5);
3144 stl_cd1400setreg(portp, MCOR1, mcor1);
3145 stl_cd1400setreg(portp, MCOR2, mcor2);
3147 stl_cd1400setreg(portp, TCOR, clk);
3148 stl_cd1400setreg(portp, TBPR, div);
3149 stl_cd1400setreg(portp, RCOR, clk);
3150 stl_cd1400setreg(portp, RBPR, div);
3152 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3153 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3154 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3155 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3156 stl_cd1400setreg(portp, RTPR, rtpr);
3157 mcor1 = stl_cd1400getreg(portp, MSVR1);
3158 if (mcor1 & MSVR1_DCD)
3159 portp->sigs |= TIOCM_CD;
3161 portp->sigs &= ~TIOCM_CD;
3162 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3163 BRDDISABLE(portp->brdnr);
3164 spin_unlock_irqrestore(&brd_lock, flags);
3167 /*****************************************************************************/
3170 * Set the state of the DTR and RTS signals.
3173 static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts)
3175 unsigned char msvr1, msvr2;
3176 unsigned long flags;
3178 pr_debug("stl_cd1400setsignals(portp=%p,dtr=%d,rts=%d)\n",
3188 spin_lock_irqsave(&brd_lock, flags);
3189 BRDENABLE(portp->brdnr, portp->pagenr);
3190 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3192 stl_cd1400setreg(portp, MSVR2, msvr2);
3194 stl_cd1400setreg(portp, MSVR1, msvr1);
3195 BRDDISABLE(portp->brdnr);
3196 spin_unlock_irqrestore(&brd_lock, flags);
3199 /*****************************************************************************/
3202 * Return the state of the signals.
3205 static int stl_cd1400getsignals(struct stlport *portp)
3207 unsigned char msvr1, msvr2;
3208 unsigned long flags;
3211 pr_debug("stl_cd1400getsignals(portp=%p)\n", portp);
3213 spin_lock_irqsave(&brd_lock, flags);
3214 BRDENABLE(portp->brdnr, portp->pagenr);
3215 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3216 msvr1 = stl_cd1400getreg(portp, MSVR1);
3217 msvr2 = stl_cd1400getreg(portp, MSVR2);
3218 BRDDISABLE(portp->brdnr);
3219 spin_unlock_irqrestore(&brd_lock, flags);
3222 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3223 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3224 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3225 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3227 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3228 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3235 /*****************************************************************************/
3238 * Enable/Disable the Transmitter and/or Receiver.
3241 static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx)
3244 unsigned long flags;
3246 pr_debug("stl_cd1400enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
3251 ccr |= CCR_TXDISABLE;
3253 ccr |= CCR_TXENABLE;
3255 ccr |= CCR_RXDISABLE;
3257 ccr |= CCR_RXENABLE;
3259 spin_lock_irqsave(&brd_lock, flags);
3260 BRDENABLE(portp->brdnr, portp->pagenr);
3261 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3262 stl_cd1400ccrwait(portp);
3263 stl_cd1400setreg(portp, CCR, ccr);
3264 stl_cd1400ccrwait(portp);
3265 BRDDISABLE(portp->brdnr);
3266 spin_unlock_irqrestore(&brd_lock, flags);
3269 /*****************************************************************************/
3272 * Start/stop the Transmitter and/or Receiver.
3275 static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx)
3277 unsigned char sreron, sreroff;
3278 unsigned long flags;
3280 pr_debug("stl_cd1400startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
3285 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3287 sreron |= SRER_TXDATA;
3289 sreron |= SRER_TXEMPTY;
3291 sreroff |= SRER_RXDATA;
3293 sreron |= SRER_RXDATA;
3295 spin_lock_irqsave(&brd_lock, flags);
3296 BRDENABLE(portp->brdnr, portp->pagenr);
3297 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3298 stl_cd1400setreg(portp, SRER,
3299 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3300 BRDDISABLE(portp->brdnr);
3302 set_bit(ASYI_TXBUSY, &portp->istate);
3303 spin_unlock_irqrestore(&brd_lock, flags);
3306 /*****************************************************************************/
3309 * Disable all interrupts from this port.
3312 static void stl_cd1400disableintrs(struct stlport *portp)
3314 unsigned long flags;
3316 pr_debug("stl_cd1400disableintrs(portp=%p)\n", portp);
3318 spin_lock_irqsave(&brd_lock, flags);
3319 BRDENABLE(portp->brdnr, portp->pagenr);
3320 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3321 stl_cd1400setreg(portp, SRER, 0);
3322 BRDDISABLE(portp->brdnr);
3323 spin_unlock_irqrestore(&brd_lock, flags);
3326 /*****************************************************************************/
3328 static void stl_cd1400sendbreak(struct stlport *portp, int len)
3330 unsigned long flags;
3332 pr_debug("stl_cd1400sendbreak(portp=%p,len=%d)\n", portp, len);
3334 spin_lock_irqsave(&brd_lock, flags);
3335 BRDENABLE(portp->brdnr, portp->pagenr);
3336 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3337 stl_cd1400setreg(portp, SRER,
3338 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3340 BRDDISABLE(portp->brdnr);
3341 portp->brklen = len;
3343 portp->stats.txbreaks++;
3344 spin_unlock_irqrestore(&brd_lock, flags);
3347 /*****************************************************************************/
3350 * Take flow control actions...
3353 static void stl_cd1400flowctrl(struct stlport *portp, int state)
3355 struct tty_struct *tty;
3356 unsigned long flags;
3358 pr_debug("stl_cd1400flowctrl(portp=%p,state=%x)\n", portp, state);
3366 spin_lock_irqsave(&brd_lock, flags);
3367 BRDENABLE(portp->brdnr, portp->pagenr);
3368 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3371 if (tty->termios->c_iflag & IXOFF) {
3372 stl_cd1400ccrwait(portp);
3373 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3374 portp->stats.rxxon++;
3375 stl_cd1400ccrwait(portp);
3378 * Question: should we return RTS to what it was before? It may
3379 * have been set by an ioctl... Suppose not, since if you have
3380 * hardware flow control set then it is pretty silly to go and
3381 * set the RTS line by hand.
3383 if (tty->termios->c_cflag & CRTSCTS) {
3384 stl_cd1400setreg(portp, MCOR1,
3385 (stl_cd1400getreg(portp, MCOR1) |
3386 FIFO_RTSTHRESHOLD));
3387 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3388 portp->stats.rxrtson++;
3391 if (tty->termios->c_iflag & IXOFF) {
3392 stl_cd1400ccrwait(portp);
3393 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3394 portp->stats.rxxoff++;
3395 stl_cd1400ccrwait(portp);
3397 if (tty->termios->c_cflag & CRTSCTS) {
3398 stl_cd1400setreg(portp, MCOR1,
3399 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3400 stl_cd1400setreg(portp, MSVR2, 0);
3401 portp->stats.rxrtsoff++;
3405 BRDDISABLE(portp->brdnr);
3406 spin_unlock_irqrestore(&brd_lock, flags);
3409 /*****************************************************************************/
3412 * Send a flow control character...
3415 static void stl_cd1400sendflow(struct stlport *portp, int state)
3417 struct tty_struct *tty;
3418 unsigned long flags;
3420 pr_debug("stl_cd1400sendflow(portp=%p,state=%x)\n", portp, state);
3428 spin_lock_irqsave(&brd_lock, flags);
3429 BRDENABLE(portp->brdnr, portp->pagenr);
3430 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3432 stl_cd1400ccrwait(portp);
3433 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3434 portp->stats.rxxon++;
3435 stl_cd1400ccrwait(portp);
3437 stl_cd1400ccrwait(portp);
3438 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3439 portp->stats.rxxoff++;
3440 stl_cd1400ccrwait(portp);
3442 BRDDISABLE(portp->brdnr);
3443 spin_unlock_irqrestore(&brd_lock, flags);
3446 /*****************************************************************************/
3448 static void stl_cd1400flush(struct stlport *portp)
3450 unsigned long flags;
3452 pr_debug("stl_cd1400flush(portp=%p)\n", portp);
3457 spin_lock_irqsave(&brd_lock, flags);
3458 BRDENABLE(portp->brdnr, portp->pagenr);
3459 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3460 stl_cd1400ccrwait(portp);
3461 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3462 stl_cd1400ccrwait(portp);
3463 portp->tx.tail = portp->tx.head;
3464 BRDDISABLE(portp->brdnr);
3465 spin_unlock_irqrestore(&brd_lock, flags);
3468 /*****************************************************************************/
3471 * Return the current state of data flow on this port. This is only
3472 * really interresting when determining if data has fully completed
3473 * transmission or not... This is easy for the cd1400, it accurately
3474 * maintains the busy port flag.
3477 static int stl_cd1400datastate(struct stlport *portp)
3479 pr_debug("stl_cd1400datastate(portp=%p)\n", portp);
3484 return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
3487 /*****************************************************************************/
3490 * Interrupt service routine for cd1400 EasyIO boards.
3493 static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase)
3495 unsigned char svrtype;
3497 pr_debug("stl_cd1400eiointr(panelp=%p,iobase=%x)\n", panelp, iobase);
3499 spin_lock(&brd_lock);
3501 svrtype = inb(iobase + EREG_DATA);
3502 if (panelp->nrports > 4) {
3503 outb((SVRR + 0x80), iobase);
3504 svrtype |= inb(iobase + EREG_DATA);
3507 if (svrtype & SVRR_RX)
3508 stl_cd1400rxisr(panelp, iobase);
3509 else if (svrtype & SVRR_TX)
3510 stl_cd1400txisr(panelp, iobase);
3511 else if (svrtype & SVRR_MDM)
3512 stl_cd1400mdmisr(panelp, iobase);
3514 spin_unlock(&brd_lock);
3517 /*****************************************************************************/
3520 * Interrupt service routine for cd1400 panels.
3523 static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase)
3525 unsigned char svrtype;
3527 pr_debug("stl_cd1400echintr(panelp=%p,iobase=%x)\n", panelp, iobase);
3530 svrtype = inb(iobase + EREG_DATA);
3531 outb((SVRR + 0x80), iobase);
3532 svrtype |= inb(iobase + EREG_DATA);
3533 if (svrtype & SVRR_RX)
3534 stl_cd1400rxisr(panelp, iobase);
3535 else if (svrtype & SVRR_TX)
3536 stl_cd1400txisr(panelp, iobase);
3537 else if (svrtype & SVRR_MDM)
3538 stl_cd1400mdmisr(panelp, iobase);
3542 /*****************************************************************************/
3545 * Unfortunately we need to handle breaks in the TX data stream, since
3546 * this is the only way to generate them on the cd1400.
3549 static int stl_cd1400breakisr(struct stlport *portp, int ioaddr)
3551 if (portp->brklen == 1) {
3552 outb((COR2 + portp->uartaddr), ioaddr);
3553 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
3554 (ioaddr + EREG_DATA));
3555 outb((TDR + portp->uartaddr), ioaddr);
3556 outb(ETC_CMD, (ioaddr + EREG_DATA));
3557 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
3558 outb((SRER + portp->uartaddr), ioaddr);
3559 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
3560 (ioaddr + EREG_DATA));
3562 } else if (portp->brklen > 1) {
3563 outb((TDR + portp->uartaddr), ioaddr);
3564 outb(ETC_CMD, (ioaddr + EREG_DATA));
3565 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
3569 outb((COR2 + portp->uartaddr), ioaddr);
3570 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
3571 (ioaddr + EREG_DATA));
3577 /*****************************************************************************/
3580 * Transmit interrupt handler. This has gotta be fast! Handling TX
3581 * chars is pretty simple, stuff as many as possible from the TX buffer
3582 * into the cd1400 FIFO. Must also handle TX breaks here, since they
3583 * are embedded as commands in the data stream. Oh no, had to use a goto!
3584 * This could be optimized more, will do when I get time...
3585 * In practice it is possible that interrupts are enabled but that the
3586 * port has been hung up. Need to handle not having any TX buffer here,
3587 * this is done by using the side effect that head and tail will also
3588 * be NULL if the buffer has been freed.
3591 static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr)
3593 struct stlport *portp;
3596 unsigned char ioack, srer;
3598 pr_debug("stl_cd1400txisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3600 ioack = inb(ioaddr + EREG_TXACK);
3601 if (((ioack & panelp->ackmask) != 0) ||
3602 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
3603 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
3606 portp = panelp->ports[(ioack >> 3)];
3609 * Unfortunately we need to handle breaks in the data stream, since
3610 * this is the only way to generate them on the cd1400. Do it now if
3611 * a break is to be sent.
3613 if (portp->brklen != 0)
3614 if (stl_cd1400breakisr(portp, ioaddr))
3617 head = portp->tx.head;
3618 tail = portp->tx.tail;
3619 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
3620 if ((len == 0) || ((len < STL_TXBUFLOW) &&
3621 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
3622 set_bit(ASYI_TXLOW, &portp->istate);
3623 schedule_work(&portp->tqueue);
3627 outb((SRER + portp->uartaddr), ioaddr);
3628 srer = inb(ioaddr + EREG_DATA);
3629 if (srer & SRER_TXDATA) {
3630 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
3632 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
3633 clear_bit(ASYI_TXBUSY, &portp->istate);
3635 outb(srer, (ioaddr + EREG_DATA));
3637 len = MIN(len, CD1400_TXFIFOSIZE);
3638 portp->stats.txtotal += len;
3639 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
3640 outb((TDR + portp->uartaddr), ioaddr);
3641 outsb((ioaddr + EREG_DATA), tail, stlen);
3644 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
3645 tail = portp->tx.buf;
3647 outsb((ioaddr + EREG_DATA), tail, len);
3650 portp->tx.tail = tail;
3654 outb((EOSRR + portp->uartaddr), ioaddr);
3655 outb(0, (ioaddr + EREG_DATA));
3658 /*****************************************************************************/
3661 * Receive character interrupt handler. Determine if we have good chars
3662 * or bad chars and then process appropriately. Good chars are easy
3663 * just shove the lot into the RX buffer and set all status byte to 0.
3664 * If a bad RX char then process as required. This routine needs to be
3665 * fast! In practice it is possible that we get an interrupt on a port
3666 * that is closed. This can happen on hangups - since they completely
3667 * shutdown a port not in user context. Need to handle this case.
3670 static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr)
3672 struct stlport *portp;
3673 struct tty_struct *tty;
3674 unsigned int ioack, len, buflen;
3675 unsigned char status;
3678 pr_debug("stl_cd1400rxisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3680 ioack = inb(ioaddr + EREG_RXACK);
3681 if ((ioack & panelp->ackmask) != 0) {
3682 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
3685 portp = panelp->ports[(ioack >> 3)];
3688 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
3689 outb((RDCR + portp->uartaddr), ioaddr);
3690 len = inb(ioaddr + EREG_DATA);
3691 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
3692 len = MIN(len, sizeof(stl_unwanted));
3693 outb((RDSR + portp->uartaddr), ioaddr);
3694 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
3695 portp->stats.rxlost += len;
3696 portp->stats.rxtotal += len;
3698 len = MIN(len, buflen);
3701 outb((RDSR + portp->uartaddr), ioaddr);
3702 tty_prepare_flip_string(tty, &ptr, len);
3703 insb((ioaddr + EREG_DATA), ptr, len);
3704 tty_schedule_flip(tty);
3705 portp->stats.rxtotal += len;
3708 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
3709 outb((RDSR + portp->uartaddr), ioaddr);
3710 status = inb(ioaddr + EREG_DATA);
3711 ch = inb(ioaddr + EREG_DATA);
3712 if (status & ST_PARITY)
3713 portp->stats.rxparity++;
3714 if (status & ST_FRAMING)
3715 portp->stats.rxframing++;
3716 if (status & ST_OVERRUN)
3717 portp->stats.rxoverrun++;
3718 if (status & ST_BREAK)
3719 portp->stats.rxbreaks++;
3720 if (status & ST_SCHARMASK) {
3721 if ((status & ST_SCHARMASK) == ST_SCHAR1)
3722 portp->stats.txxon++;
3723 if ((status & ST_SCHARMASK) == ST_SCHAR2)
3724 portp->stats.txxoff++;
3727 if (tty != NULL && (portp->rxignoremsk & status) == 0) {
3728 if (portp->rxmarkmsk & status) {
3729 if (status & ST_BREAK) {
3731 if (portp->flags & ASYNC_SAK) {
3733 BRDENABLE(portp->brdnr, portp->pagenr);
3735 } else if (status & ST_PARITY) {
3736 status = TTY_PARITY;
3737 } else if (status & ST_FRAMING) {
3739 } else if(status & ST_OVERRUN) {
3740 status = TTY_OVERRUN;
3747 tty_insert_flip_char(tty, ch, status);
3748 tty_schedule_flip(tty);
3751 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
3756 outb((EOSRR + portp->uartaddr), ioaddr);
3757 outb(0, (ioaddr + EREG_DATA));
3760 /*****************************************************************************/
3763 * Modem interrupt handler. The is called when the modem signal line
3764 * (DCD) has changed state. Leave most of the work to the off-level
3765 * processing routine.
3768 static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr)
3770 struct stlport *portp;
3774 pr_debug("stl_cd1400mdmisr(panelp=%p)\n", panelp);
3776 ioack = inb(ioaddr + EREG_MDACK);
3777 if (((ioack & panelp->ackmask) != 0) ||
3778 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
3779 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
3782 portp = panelp->ports[(ioack >> 3)];
3784 outb((MISR + portp->uartaddr), ioaddr);
3785 misr = inb(ioaddr + EREG_DATA);
3786 if (misr & MISR_DCD) {
3787 set_bit(ASYI_DCDCHANGE, &portp->istate);
3788 schedule_work(&portp->tqueue);
3789 portp->stats.modem++;
3792 outb((EOSRR + portp->uartaddr), ioaddr);
3793 outb(0, (ioaddr + EREG_DATA));
3796 /*****************************************************************************/
3797 /* SC26198 HARDWARE FUNCTIONS */
3798 /*****************************************************************************/
3801 * These functions get/set/update the registers of the sc26198 UARTs.
3802 * Access to the sc26198 registers is via an address/data io port pair.
3803 * (Maybe should make this inline...)
3806 static int stl_sc26198getreg(struct stlport *portp, int regnr)
3808 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3809 return inb(portp->ioaddr + XP_DATA);
3812 static void stl_sc26198setreg(struct stlport *portp, int regnr, int value)
3814 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3815 outb(value, (portp->ioaddr + XP_DATA));
3818 static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value)
3820 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3821 if (inb(portp->ioaddr + XP_DATA) != value) {
3822 outb(value, (portp->ioaddr + XP_DATA));
3828 /*****************************************************************************/
3831 * Functions to get and set the sc26198 global registers.
3834 static int stl_sc26198getglobreg(struct stlport *portp, int regnr)
3836 outb(regnr, (portp->ioaddr + XP_ADDR));
3837 return inb(portp->ioaddr + XP_DATA);
3841 static void stl_sc26198setglobreg(struct stlport *portp, int regnr, int value)
3843 outb(regnr, (portp->ioaddr + XP_ADDR));
3844 outb(value, (portp->ioaddr + XP_DATA));
3848 /*****************************************************************************/
3851 * Inbitialize the UARTs in a panel. We don't care what sort of board
3852 * these ports are on - since the port io registers are almost
3853 * identical when dealing with ports.
3856 static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
3859 int nrchips, ioaddr;
3861 pr_debug("stl_sc26198panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
3863 BRDENABLE(panelp->brdnr, panelp->pagenr);
3866 * Check that each chip is present and started up OK.
3869 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
3870 if (brdp->brdtype == BRD_ECHPCI)
3871 outb(panelp->pagenr, brdp->ioctrl);
3873 for (i = 0; (i < nrchips); i++) {
3874 ioaddr = panelp->iobase + (i * 4);
3875 outb(SCCR, (ioaddr + XP_ADDR));
3876 outb(CR_RESETALL, (ioaddr + XP_DATA));
3877 outb(TSTR, (ioaddr + XP_ADDR));
3878 if (inb(ioaddr + XP_DATA) != 0) {
3879 printk("STALLION: sc26198 not responding, "
3880 "brd=%d panel=%d chip=%d\n",
3881 panelp->brdnr, panelp->panelnr, i);
3884 chipmask |= (0x1 << i);
3885 outb(GCCR, (ioaddr + XP_ADDR));
3886 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
3887 outb(WDTRCR, (ioaddr + XP_ADDR));
3888 outb(0xff, (ioaddr + XP_DATA));
3891 BRDDISABLE(panelp->brdnr);
3895 /*****************************************************************************/
3898 * Initialize hardware specific port registers.
3901 static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
3903 pr_debug("stl_sc26198portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
3906 if ((brdp == NULL) || (panelp == NULL) ||
3910 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
3911 portp->uartaddr = (portp->portnr & 0x07) << 4;
3912 portp->pagenr = panelp->pagenr;
3915 BRDENABLE(portp->brdnr, portp->pagenr);
3916 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
3917 BRDDISABLE(portp->brdnr);
3920 /*****************************************************************************/
3923 * Set up the sc26198 registers for a port based on the termios port
3927 static void stl_sc26198setport(struct stlport *portp, struct termios *tiosp)
3929 struct stlbrd *brdp;
3930 unsigned long flags;
3931 unsigned int baudrate;
3932 unsigned char mr0, mr1, mr2, clk;
3933 unsigned char imron, imroff, iopr, ipr;
3943 brdp = stl_brds[portp->brdnr];
3948 * Set up the RX char ignore mask with those RX error types we
3951 portp->rxignoremsk = 0;
3952 if (tiosp->c_iflag & IGNPAR)
3953 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
3955 if (tiosp->c_iflag & IGNBRK)
3956 portp->rxignoremsk |= SR_RXBREAK;
3958 portp->rxmarkmsk = SR_RXOVERRUN;
3959 if (tiosp->c_iflag & (INPCK | PARMRK))
3960 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
3961 if (tiosp->c_iflag & BRKINT)
3962 portp->rxmarkmsk |= SR_RXBREAK;
3965 * Go through the char size, parity and stop bits and set all the
3966 * option register appropriately.
3968 switch (tiosp->c_cflag & CSIZE) {
3983 if (tiosp->c_cflag & CSTOPB)
3988 if (tiosp->c_cflag & PARENB) {
3989 if (tiosp->c_cflag & PARODD)
3990 mr1 |= (MR1_PARENB | MR1_PARODD);
3992 mr1 |= (MR1_PARENB | MR1_PAREVEN);
3997 mr1 |= MR1_ERRBLOCK;
4000 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4001 * space for hardware flow control and the like. This should be set to
4004 mr2 |= MR2_RXFIFOHALF;
4007 * Calculate the baud rate timers. For now we will just assume that
4008 * the input and output baud are the same. The sc26198 has a fixed
4009 * baud rate table, so only discrete baud rates possible.
4011 baudrate = tiosp->c_cflag & CBAUD;
4012 if (baudrate & CBAUDEX) {
4013 baudrate &= ~CBAUDEX;
4014 if ((baudrate < 1) || (baudrate > 4))
4015 tiosp->c_cflag &= ~CBAUDEX;
4019 baudrate = stl_baudrates[baudrate];
4020 if ((tiosp->c_cflag & CBAUD) == B38400) {
4021 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
4023 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
4025 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
4027 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
4029 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
4030 baudrate = (portp->baud_base / portp->custom_divisor);
4032 if (baudrate > STL_SC26198MAXBAUD)
4033 baudrate = STL_SC26198MAXBAUD;
4036 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
4037 if (baudrate <= sc26198_baudtable[clk])
4043 * Check what form of modem signaling is required and set it up.
4045 if (tiosp->c_cflag & CLOCAL) {
4046 portp->flags &= ~ASYNC_CHECK_CD;
4048 iopr |= IOPR_DCDCOS;
4050 portp->flags |= ASYNC_CHECK_CD;
4054 * Setup sc26198 enhanced modes if we can. In particular we want to
4055 * handle as much of the flow control as possible automatically. As
4056 * well as saving a few CPU cycles it will also greatly improve flow
4057 * control reliability.
4059 if (tiosp->c_iflag & IXON) {
4060 mr0 |= MR0_SWFTX | MR0_SWFT;
4061 imron |= IR_XONXOFF;
4063 imroff |= IR_XONXOFF;
4065 if (tiosp->c_iflag & IXOFF)
4068 if (tiosp->c_cflag & CRTSCTS) {
4074 * All sc26198 register values calculated so go through and set
4078 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4079 portp->portnr, portp->panelnr, portp->brdnr);
4080 pr_debug(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4081 pr_debug(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4082 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4083 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4084 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4086 spin_lock_irqsave(&brd_lock, flags);
4087 BRDENABLE(portp->brdnr, portp->pagenr);
4088 stl_sc26198setreg(portp, IMR, 0);
4089 stl_sc26198updatereg(portp, MR0, mr0);
4090 stl_sc26198updatereg(portp, MR1, mr1);
4091 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4092 stl_sc26198updatereg(portp, MR2, mr2);
4093 stl_sc26198updatereg(portp, IOPIOR,
4094 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
4097 stl_sc26198setreg(portp, TXCSR, clk);
4098 stl_sc26198setreg(portp, RXCSR, clk);
4101 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4102 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4104 ipr = stl_sc26198getreg(portp, IPR);
4106 portp->sigs &= ~TIOCM_CD;
4108 portp->sigs |= TIOCM_CD;
4110 portp->imr = (portp->imr & ~imroff) | imron;
4111 stl_sc26198setreg(portp, IMR, portp->imr);
4112 BRDDISABLE(portp->brdnr);
4113 spin_unlock_irqrestore(&brd_lock, flags);
4116 /*****************************************************************************/
4119 * Set the state of the DTR and RTS signals.
4122 static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts)
4124 unsigned char iopioron, iopioroff;
4125 unsigned long flags;
4127 pr_debug("stl_sc26198setsignals(portp=%p,dtr=%d,rts=%d)\n", portp,
4133 iopioroff |= IPR_DTR;
4135 iopioron |= IPR_DTR;
4137 iopioroff |= IPR_RTS;
4139 iopioron |= IPR_RTS;
4141 spin_lock_irqsave(&brd_lock, flags);
4142 BRDENABLE(portp->brdnr, portp->pagenr);
4143 stl_sc26198setreg(portp, IOPIOR,
4144 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4145 BRDDISABLE(portp->brdnr);
4146 spin_unlock_irqrestore(&brd_lock, flags);
4149 /*****************************************************************************/
4152 * Return the state of the signals.
4155 static int stl_sc26198getsignals(struct stlport *portp)
4158 unsigned long flags;
4161 pr_debug("stl_sc26198getsignals(portp=%p)\n", portp);
4163 spin_lock_irqsave(&brd_lock, flags);
4164 BRDENABLE(portp->brdnr, portp->pagenr);
4165 ipr = stl_sc26198getreg(portp, IPR);
4166 BRDDISABLE(portp->brdnr);
4167 spin_unlock_irqrestore(&brd_lock, flags);
4170 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4171 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4172 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4173 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4178 /*****************************************************************************/
4181 * Enable/Disable the Transmitter and/or Receiver.
4184 static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx)
4187 unsigned long flags;
4189 pr_debug("stl_sc26198enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx,tx);
4191 ccr = portp->crenable;
4193 ccr &= ~CR_TXENABLE;
4197 ccr &= ~CR_RXENABLE;
4201 spin_lock_irqsave(&brd_lock, flags);
4202 BRDENABLE(portp->brdnr, portp->pagenr);
4203 stl_sc26198setreg(portp, SCCR, ccr);
4204 BRDDISABLE(portp->brdnr);
4205 portp->crenable = ccr;
4206 spin_unlock_irqrestore(&brd_lock, flags);
4209 /*****************************************************************************/
4212 * Start/stop the Transmitter and/or Receiver.
4215 static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx)
4218 unsigned long flags;
4220 pr_debug("stl_sc26198startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
4228 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4230 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4232 spin_lock_irqsave(&brd_lock, flags);
4233 BRDENABLE(portp->brdnr, portp->pagenr);
4234 stl_sc26198setreg(portp, IMR, imr);
4235 BRDDISABLE(portp->brdnr);
4238 set_bit(ASYI_TXBUSY, &portp->istate);
4239 spin_unlock_irqrestore(&brd_lock, flags);
4242 /*****************************************************************************/
4245 * Disable all interrupts from this port.
4248 static void stl_sc26198disableintrs(struct stlport *portp)
4250 unsigned long flags;
4252 pr_debug("stl_sc26198disableintrs(portp=%p)\n", portp);
4254 spin_lock_irqsave(&brd_lock, flags);
4255 BRDENABLE(portp->brdnr, portp->pagenr);
4257 stl_sc26198setreg(portp, IMR, 0);
4258 BRDDISABLE(portp->brdnr);
4259 spin_unlock_irqrestore(&brd_lock, flags);
4262 /*****************************************************************************/
4264 static void stl_sc26198sendbreak(struct stlport *portp, int len)
4266 unsigned long flags;
4268 pr_debug("stl_sc26198sendbreak(portp=%p,len=%d)\n", portp, len);
4270 spin_lock_irqsave(&brd_lock, flags);
4271 BRDENABLE(portp->brdnr, portp->pagenr);
4273 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4274 portp->stats.txbreaks++;
4276 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4278 BRDDISABLE(portp->brdnr);
4279 spin_unlock_irqrestore(&brd_lock, flags);
4282 /*****************************************************************************/
4285 * Take flow control actions...
4288 static void stl_sc26198flowctrl(struct stlport *portp, int state)
4290 struct tty_struct *tty;
4291 unsigned long flags;
4294 pr_debug("stl_sc26198flowctrl(portp=%p,state=%x)\n", portp, state);
4302 spin_lock_irqsave(&brd_lock, flags);
4303 BRDENABLE(portp->brdnr, portp->pagenr);
4306 if (tty->termios->c_iflag & IXOFF) {
4307 mr0 = stl_sc26198getreg(portp, MR0);
4308 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4309 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4311 portp->stats.rxxon++;
4312 stl_sc26198wait(portp);
4313 stl_sc26198setreg(portp, MR0, mr0);
4316 * Question: should we return RTS to what it was before? It may
4317 * have been set by an ioctl... Suppose not, since if you have
4318 * hardware flow control set then it is pretty silly to go and
4319 * set the RTS line by hand.
4321 if (tty->termios->c_cflag & CRTSCTS) {
4322 stl_sc26198setreg(portp, MR1,
4323 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4324 stl_sc26198setreg(portp, IOPIOR,
4325 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4326 portp->stats.rxrtson++;
4329 if (tty->termios->c_iflag & IXOFF) {
4330 mr0 = stl_sc26198getreg(portp, MR0);
4331 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4332 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4334 portp->stats.rxxoff++;
4335 stl_sc26198wait(portp);
4336 stl_sc26198setreg(portp, MR0, mr0);
4338 if (tty->termios->c_cflag & CRTSCTS) {
4339 stl_sc26198setreg(portp, MR1,
4340 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4341 stl_sc26198setreg(portp, IOPIOR,
4342 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4343 portp->stats.rxrtsoff++;
4347 BRDDISABLE(portp->brdnr);
4348 spin_unlock_irqrestore(&brd_lock, flags);
4351 /*****************************************************************************/
4354 * Send a flow control character.
4357 static void stl_sc26198sendflow(struct stlport *portp, int state)
4359 struct tty_struct *tty;
4360 unsigned long flags;
4363 pr_debug("stl_sc26198sendflow(portp=%p,state=%x)\n", portp, state);
4371 spin_lock_irqsave(&brd_lock, flags);
4372 BRDENABLE(portp->brdnr, portp->pagenr);
4374 mr0 = stl_sc26198getreg(portp, MR0);
4375 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4376 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4378 portp->stats.rxxon++;
4379 stl_sc26198wait(portp);
4380 stl_sc26198setreg(portp, MR0, mr0);
4382 mr0 = stl_sc26198getreg(portp, MR0);
4383 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4384 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4386 portp->stats.rxxoff++;
4387 stl_sc26198wait(portp);
4388 stl_sc26198setreg(portp, MR0, mr0);
4390 BRDDISABLE(portp->brdnr);
4391 spin_unlock_irqrestore(&brd_lock, flags);
4394 /*****************************************************************************/
4396 static void stl_sc26198flush(struct stlport *portp)
4398 unsigned long flags;
4400 pr_debug("stl_sc26198flush(portp=%p)\n", portp);
4405 spin_lock_irqsave(&brd_lock, flags);
4406 BRDENABLE(portp->brdnr, portp->pagenr);
4407 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4408 stl_sc26198setreg(portp, SCCR, portp->crenable);
4409 BRDDISABLE(portp->brdnr);
4410 portp->tx.tail = portp->tx.head;
4411 spin_unlock_irqrestore(&brd_lock, flags);
4414 /*****************************************************************************/
4417 * Return the current state of data flow on this port. This is only
4418 * really interresting when determining if data has fully completed
4419 * transmission or not... The sc26198 interrupt scheme cannot
4420 * determine when all data has actually drained, so we need to
4421 * check the port statusy register to be sure.
4424 static int stl_sc26198datastate(struct stlport *portp)
4426 unsigned long flags;
4429 pr_debug("stl_sc26198datastate(portp=%p)\n", portp);
4433 if (test_bit(ASYI_TXBUSY, &portp->istate))
4436 spin_lock_irqsave(&brd_lock, flags);
4437 BRDENABLE(portp->brdnr, portp->pagenr);
4438 sr = stl_sc26198getreg(portp, SR);
4439 BRDDISABLE(portp->brdnr);
4440 spin_unlock_irqrestore(&brd_lock, flags);
4442 return (sr & SR_TXEMPTY) ? 0 : 1;
4445 /*****************************************************************************/
4448 * Delay for a small amount of time, to give the sc26198 a chance
4449 * to process a command...
4452 static void stl_sc26198wait(struct stlport *portp)
4456 pr_debug("stl_sc26198wait(portp=%p)\n", portp);
4461 for (i = 0; (i < 20); i++)
4462 stl_sc26198getglobreg(portp, TSTR);
4465 /*****************************************************************************/
4468 * If we are TX flow controlled and in IXANY mode then we may
4469 * need to unflow control here. We gotta do this because of the
4470 * automatic flow control modes of the sc26198.
4473 static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty)
4477 mr0 = stl_sc26198getreg(portp, MR0);
4478 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4479 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4480 stl_sc26198wait(portp);
4481 stl_sc26198setreg(portp, MR0, mr0);
4482 clear_bit(ASYI_TXFLOWED, &portp->istate);
4485 /*****************************************************************************/
4488 * Interrupt service routine for sc26198 panels.
4491 static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase)
4493 struct stlport *portp;
4496 spin_lock(&brd_lock);
4499 * Work around bug in sc26198 chip... Cannot have A6 address
4500 * line of UART high, else iack will be returned as 0.
4502 outb(0, (iobase + 1));
4504 iack = inb(iobase + XP_IACK);
4505 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4507 if (iack & IVR_RXDATA)
4508 stl_sc26198rxisr(portp, iack);
4509 else if (iack & IVR_TXDATA)
4510 stl_sc26198txisr(portp);
4512 stl_sc26198otherisr(portp, iack);
4514 spin_unlock(&brd_lock);
4517 /*****************************************************************************/
4520 * Transmit interrupt handler. This has gotta be fast! Handling TX
4521 * chars is pretty simple, stuff as many as possible from the TX buffer
4522 * into the sc26198 FIFO.
4523 * In practice it is possible that interrupts are enabled but that the
4524 * port has been hung up. Need to handle not having any TX buffer here,
4525 * this is done by using the side effect that head and tail will also
4526 * be NULL if the buffer has been freed.
4529 static void stl_sc26198txisr(struct stlport *portp)
4531 unsigned int ioaddr;
4536 pr_debug("stl_sc26198txisr(portp=%p)\n", portp);
4538 ioaddr = portp->ioaddr;
4539 head = portp->tx.head;
4540 tail = portp->tx.tail;
4541 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4542 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4543 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4544 set_bit(ASYI_TXLOW, &portp->istate);
4545 schedule_work(&portp->tqueue);
4549 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
4550 mr0 = inb(ioaddr + XP_DATA);
4551 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4552 portp->imr &= ~IR_TXRDY;
4553 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
4554 outb(portp->imr, (ioaddr + XP_DATA));
4555 clear_bit(ASYI_TXBUSY, &portp->istate);
4557 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4558 outb(mr0, (ioaddr + XP_DATA));
4561 len = MIN(len, SC26198_TXFIFOSIZE);
4562 portp->stats.txtotal += len;
4563 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4564 outb(GTXFIFO, (ioaddr + XP_ADDR));
4565 outsb((ioaddr + XP_DATA), tail, stlen);
4568 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4569 tail = portp->tx.buf;
4571 outsb((ioaddr + XP_DATA), tail, len);
4574 portp->tx.tail = tail;
4578 /*****************************************************************************/
4581 * Receive character interrupt handler. Determine if we have good chars
4582 * or bad chars and then process appropriately. Good chars are easy
4583 * just shove the lot into the RX buffer and set all status byte to 0.
4584 * If a bad RX char then process as required. This routine needs to be
4585 * fast! In practice it is possible that we get an interrupt on a port
4586 * that is closed. This can happen on hangups - since they completely
4587 * shutdown a port not in user context. Need to handle this case.
4590 static void stl_sc26198rxisr(struct stlport *portp, unsigned int iack)
4592 struct tty_struct *tty;
4593 unsigned int len, buflen, ioaddr;
4595 pr_debug("stl_sc26198rxisr(portp=%p,iack=%x)\n", portp, iack);
4598 ioaddr = portp->ioaddr;
4599 outb(GIBCR, (ioaddr + XP_ADDR));
4600 len = inb(ioaddr + XP_DATA) + 1;
4602 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
4603 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
4604 len = MIN(len, sizeof(stl_unwanted));
4605 outb(GRXFIFO, (ioaddr + XP_ADDR));
4606 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4607 portp->stats.rxlost += len;
4608 portp->stats.rxtotal += len;
4610 len = MIN(len, buflen);
4613 outb(GRXFIFO, (ioaddr + XP_ADDR));
4614 tty_prepare_flip_string(tty, &ptr, len);
4615 insb((ioaddr + XP_DATA), ptr, len);
4616 tty_schedule_flip(tty);
4617 portp->stats.rxtotal += len;
4621 stl_sc26198rxbadchars(portp);
4625 * If we are TX flow controlled and in IXANY mode then we may need
4626 * to unflow control here. We gotta do this because of the automatic
4627 * flow control modes of the sc26198.
4629 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
4630 if ((tty != NULL) &&
4631 (tty->termios != NULL) &&
4632 (tty->termios->c_iflag & IXANY)) {
4633 stl_sc26198txunflow(portp, tty);
4638 /*****************************************************************************/
4641 * Process an RX bad character.
4644 static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch)
4646 struct tty_struct *tty;
4647 unsigned int ioaddr;
4650 ioaddr = portp->ioaddr;
4652 if (status & SR_RXPARITY)
4653 portp->stats.rxparity++;
4654 if (status & SR_RXFRAMING)
4655 portp->stats.rxframing++;
4656 if (status & SR_RXOVERRUN)
4657 portp->stats.rxoverrun++;
4658 if (status & SR_RXBREAK)
4659 portp->stats.rxbreaks++;
4661 if ((tty != NULL) &&
4662 ((portp->rxignoremsk & status) == 0)) {
4663 if (portp->rxmarkmsk & status) {
4664 if (status & SR_RXBREAK) {
4666 if (portp->flags & ASYNC_SAK) {
4668 BRDENABLE(portp->brdnr, portp->pagenr);
4670 } else if (status & SR_RXPARITY) {
4671 status = TTY_PARITY;
4672 } else if (status & SR_RXFRAMING) {
4674 } else if(status & SR_RXOVERRUN) {
4675 status = TTY_OVERRUN;
4683 tty_insert_flip_char(tty, ch, status);
4684 tty_schedule_flip(tty);
4687 portp->stats.rxtotal++;
4691 /*****************************************************************************/
4694 * Process all characters in the RX FIFO of the UART. Check all char
4695 * status bytes as well, and process as required. We need to check
4696 * all bytes in the FIFO, in case some more enter the FIFO while we
4697 * are here. To get the exact character error type we need to switch
4698 * into CHAR error mode (that is why we need to make sure we empty
4702 static void stl_sc26198rxbadchars(struct stlport *portp)
4704 unsigned char status, mr1;
4708 * To get the precise error type for each character we must switch
4709 * back into CHAR error mode.
4711 mr1 = stl_sc26198getreg(portp, MR1);
4712 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
4714 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
4715 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
4716 ch = stl_sc26198getreg(portp, RXFIFO);
4717 stl_sc26198rxbadch(portp, status, ch);
4721 * To get correct interrupt class we must switch back into BLOCK
4724 stl_sc26198setreg(portp, MR1, mr1);
4727 /*****************************************************************************/
4730 * Other interrupt handler. This includes modem signals, flow
4731 * control actions, etc. Most stuff is left to off-level interrupt
4735 static void stl_sc26198otherisr(struct stlport *portp, unsigned int iack)
4737 unsigned char cir, ipr, xisr;
4739 pr_debug("stl_sc26198otherisr(portp=%p,iack=%x)\n", portp, iack);
4741 cir = stl_sc26198getglobreg(portp, CIR);
4743 switch (cir & CIR_SUBTYPEMASK) {
4745 ipr = stl_sc26198getreg(portp, IPR);
4746 if (ipr & IPR_DCDCHANGE) {
4747 set_bit(ASYI_DCDCHANGE, &portp->istate);
4748 schedule_work(&portp->tqueue);
4749 portp->stats.modem++;
4752 case CIR_SUBXONXOFF:
4753 xisr = stl_sc26198getreg(portp, XISR);
4754 if (xisr & XISR_RXXONGOT) {
4755 set_bit(ASYI_TXFLOWED, &portp->istate);
4756 portp->stats.txxoff++;
4758 if (xisr & XISR_RXXOFFGOT) {
4759 clear_bit(ASYI_TXFLOWED, &portp->istate);
4760 portp->stats.txxon++;
4764 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
4765 stl_sc26198rxbadchars(portp);
4773 * Loadable module initialization stuff.
4775 static int __init stallion_module_init(void)
4779 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
4781 spin_lock_init(&stallion_lock);
4782 spin_lock_init(&brd_lock);
4786 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
4791 * Set up a character driver for per board stuff. This is mainly used
4792 * to do stats ioctls on the ports.
4794 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
4795 printk("STALLION: failed to register serial board device\n");
4797 stallion_class = class_create(THIS_MODULE, "staliomem");
4798 for (i = 0; i < 4; i++)
4799 class_device_create(stallion_class, NULL,
4800 MKDEV(STL_SIOMEMMAJOR, i), NULL,
4803 stl_serial->owner = THIS_MODULE;
4804 stl_serial->driver_name = stl_drvname;
4805 stl_serial->name = "ttyE";
4806 stl_serial->major = STL_SERIALMAJOR;
4807 stl_serial->minor_start = 0;
4808 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
4809 stl_serial->subtype = SERIAL_TYPE_NORMAL;
4810 stl_serial->init_termios = stl_deftermios;
4811 stl_serial->flags = TTY_DRIVER_REAL_RAW;
4812 tty_set_operations(stl_serial, &stl_ops);
4814 if (tty_register_driver(stl_serial)) {
4815 put_tty_driver(stl_serial);
4816 printk("STALLION: failed to register serial driver\n");
4823 static void __exit stallion_module_exit(void)
4825 struct stlbrd *brdp;
4826 struct stlpanel *panelp;
4827 struct stlport *portp;
4830 pr_debug("cleanup_module()\n");
4832 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
4836 * Free up all allocated resources used by the ports. This includes
4837 * memory and interrupts. As part of this process we will also do
4838 * a hangup on every open port - to try to flush out any processes
4839 * hanging onto ports.
4841 i = tty_unregister_driver(stl_serial);
4842 put_tty_driver(stl_serial);
4844 printk("STALLION: failed to un-register tty driver, "
4848 for (i = 0; i < 4; i++)
4849 class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
4850 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
4851 printk("STALLION: failed to un-register serial memory device, "
4853 class_destroy(stallion_class);
4855 for (i = 0; (i < stl_nrbrds); i++) {
4856 if ((brdp = stl_brds[i]) == NULL)
4859 free_irq(brdp->irq, brdp);
4861 for (j = 0; (j < STL_MAXPANELS); j++) {
4862 panelp = brdp->panels[j];
4865 for (k = 0; (k < STL_PORTSPERPANEL); k++) {
4866 portp = panelp->ports[k];
4869 if (portp->tty != NULL)
4870 stl_hangup(portp->tty);
4871 kfree(portp->tx.buf);
4877 release_region(brdp->ioaddr1, brdp->iosize1);
4878 if (brdp->iosize2 > 0)
4879 release_region(brdp->ioaddr2, brdp->iosize2);
4886 module_init(stallion_module_init);
4887 module_exit(stallion_module_exit);
4889 MODULE_AUTHOR("Greg Ungerer");
4890 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
4891 MODULE_LICENSE("GPL");