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 ktermios stl_deftermios = {
145 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
152 * Define global stats structures. Not used often, and can be
153 * re-used for each stats call.
155 static comstats_t stl_comstats;
156 static combrd_t stl_brdstats;
157 static struct stlbrd stl_dummybrd;
158 static struct stlport stl_dummyport;
161 * Define global place to put buffer overflow characters.
163 static char stl_unwanted[SC26198_RXFIFOSIZE];
165 /*****************************************************************************/
167 static struct stlbrd *stl_brds[STL_MAXBRDS];
170 * Per board state flags. Used with the state field of the board struct.
171 * Not really much here!
173 #define BRD_FOUND 0x1
176 * Define the port structure istate flags. These set of flags are
177 * modified at interrupt time - so setting and reseting them needs
178 * to be atomic. Use the bit clear/setting routines for this.
180 #define ASYI_TXBUSY 1
182 #define ASYI_DCDCHANGE 3
183 #define ASYI_TXFLOWED 4
186 * Define an array of board names as printable strings. Handy for
187 * referencing boards when printing trace and stuff.
189 static char *stl_brdnames[] = {
221 /*****************************************************************************/
224 * Define some string labels for arguments passed from the module
225 * load line. These allow for easy board definitions, and easy
226 * modification of the io, memory and irq resoucres.
228 static int stl_nargs = 0;
229 static char *board0[4];
230 static char *board1[4];
231 static char *board2[4];
232 static char *board3[4];
234 static char **stl_brdsp[] = {
242 * Define a set of common board names, and types. This is used to
243 * parse any module arguments.
250 { "easyio", BRD_EASYIO },
251 { "eio", BRD_EASYIO },
252 { "20", BRD_EASYIO },
253 { "ec8/32", BRD_ECH },
254 { "ec8/32-at", BRD_ECH },
255 { "ec8/32-isa", BRD_ECH },
257 { "echat", BRD_ECH },
259 { "ec8/32-mc", BRD_ECHMC },
260 { "ec8/32-mca", BRD_ECHMC },
261 { "echmc", BRD_ECHMC },
262 { "echmca", BRD_ECHMC },
264 { "ec8/32-pc", BRD_ECHPCI },
265 { "ec8/32-pci", BRD_ECHPCI },
266 { "26", BRD_ECHPCI },
267 { "ec8/64-pc", BRD_ECH64PCI },
268 { "ec8/64-pci", BRD_ECH64PCI },
269 { "ech-pci", BRD_ECH64PCI },
270 { "echpci", BRD_ECH64PCI },
271 { "echpc", BRD_ECH64PCI },
272 { "27", BRD_ECH64PCI },
273 { "easyio-pc", BRD_EASYIOPCI },
274 { "easyio-pci", BRD_EASYIOPCI },
275 { "eio-pci", BRD_EASYIOPCI },
276 { "eiopci", BRD_EASYIOPCI },
277 { "28", BRD_EASYIOPCI },
281 * Define the module agruments.
284 module_param_array(board0, charp, &stl_nargs, 0);
285 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
286 module_param_array(board1, charp, &stl_nargs, 0);
287 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
288 module_param_array(board2, charp, &stl_nargs, 0);
289 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
290 module_param_array(board3, charp, &stl_nargs, 0);
291 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
293 /*****************************************************************************/
296 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
297 * to the directly accessible io ports of these boards (not the uarts -
298 * they are in cd1400.h and sc26198.h).
300 #define EIO_8PORTRS 0x04
301 #define EIO_4PORTRS 0x05
302 #define EIO_8PORTDI 0x00
303 #define EIO_8PORTM 0x06
305 #define EIO_IDBITMASK 0x07
307 #define EIO_BRDMASK 0xf0
310 #define ID_BRD16 0x30
312 #define EIO_INTRPEND 0x08
313 #define EIO_INTEDGE 0x00
314 #define EIO_INTLEVEL 0x08
318 #define ECH_IDBITMASK 0xe0
319 #define ECH_BRDENABLE 0x08
320 #define ECH_BRDDISABLE 0x00
321 #define ECH_INTENABLE 0x01
322 #define ECH_INTDISABLE 0x00
323 #define ECH_INTLEVEL 0x02
324 #define ECH_INTEDGE 0x00
325 #define ECH_INTRPEND 0x01
326 #define ECH_BRDRESET 0x01
328 #define ECHMC_INTENABLE 0x01
329 #define ECHMC_BRDRESET 0x02
331 #define ECH_PNLSTATUS 2
332 #define ECH_PNL16PORT 0x20
333 #define ECH_PNLIDMASK 0x07
334 #define ECH_PNLXPID 0x40
335 #define ECH_PNLINTRPEND 0x80
337 #define ECH_ADDR2MASK 0x1e0
340 * Define the vector mapping bits for the programmable interrupt board
341 * hardware. These bits encode the interrupt for the board to use - it
342 * is software selectable (except the EIO-8M).
344 static unsigned char stl_vecmap[] = {
345 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
346 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
350 * Lock ordering is that you may not take stallion_lock holding
354 static spinlock_t brd_lock; /* Guard the board mapping */
355 static spinlock_t stallion_lock; /* Guard the tty driver */
358 * Set up enable and disable macros for the ECH boards. They require
359 * the secondary io address space to be activated and deactivated.
360 * This way all ECH boards can share their secondary io region.
361 * If this is an ECH-PCI board then also need to set the page pointer
362 * to point to the correct page.
364 #define BRDENABLE(brdnr,pagenr) \
365 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
366 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
367 stl_brds[(brdnr)]->ioctrl); \
368 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
369 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
371 #define BRDDISABLE(brdnr) \
372 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
373 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
374 stl_brds[(brdnr)]->ioctrl);
376 #define STL_CD1400MAXBAUD 230400
377 #define STL_SC26198MAXBAUD 460800
379 #define STL_BAUDBASE 115200
380 #define STL_CLOSEDELAY (5 * HZ / 10)
382 /*****************************************************************************/
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.
404 static struct pci_device_id stl_pcibrds[] = {
405 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864),
406 .driver_data = BRD_ECH64PCI },
407 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI),
408 .driver_data = BRD_EASYIOPCI },
409 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832),
410 .driver_data = BRD_ECHPCI },
411 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410),
412 .driver_data = BRD_ECHPCI },
415 MODULE_DEVICE_TABLE(pci, stl_pcibrds);
417 /*****************************************************************************/
420 * Define macros to extract a brd/port number from a minor number.
422 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
423 #define MINOR2PORT(min) ((min) & 0x3f)
426 * Define a baud rate table that converts termios baud rate selector
427 * into the actual baud rate value. All baud rate calculations are
428 * based on the actual baud rate required.
430 static unsigned int stl_baudrates[] = {
431 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
432 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
436 * Define some handy local macros...
439 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
442 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
444 /*****************************************************************************/
447 * Declare all those functions in this driver!
450 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
451 static int stl_brdinit(struct stlbrd *brdp);
452 static int stl_getportstats(struct stlport *portp, comstats_t __user *cp);
453 static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp);
454 static int stl_waitcarrier(struct stlport *portp, struct file *filp);
457 * CD1400 uart specific handling functions.
459 static void stl_cd1400setreg(struct stlport *portp, int regnr, int value);
460 static int stl_cd1400getreg(struct stlport *portp, int regnr);
461 static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value);
462 static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
463 static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
464 static void stl_cd1400setport(struct stlport *portp, struct ktermios *tiosp);
465 static int stl_cd1400getsignals(struct stlport *portp);
466 static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts);
467 static void stl_cd1400ccrwait(struct stlport *portp);
468 static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx);
469 static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx);
470 static void stl_cd1400disableintrs(struct stlport *portp);
471 static void stl_cd1400sendbreak(struct stlport *portp, int len);
472 static void stl_cd1400flowctrl(struct stlport *portp, int state);
473 static void stl_cd1400sendflow(struct stlport *portp, int state);
474 static void stl_cd1400flush(struct stlport *portp);
475 static int stl_cd1400datastate(struct stlport *portp);
476 static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase);
477 static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase);
478 static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr);
479 static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr);
480 static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr);
482 static inline int stl_cd1400breakisr(struct stlport *portp, int ioaddr);
485 * SC26198 uart specific handling functions.
487 static void stl_sc26198setreg(struct stlport *portp, int regnr, int value);
488 static int stl_sc26198getreg(struct stlport *portp, int regnr);
489 static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value);
490 static int stl_sc26198getglobreg(struct stlport *portp, int regnr);
491 static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
492 static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
493 static void stl_sc26198setport(struct stlport *portp, struct ktermios *tiosp);
494 static int stl_sc26198getsignals(struct stlport *portp);
495 static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts);
496 static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx);
497 static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx);
498 static void stl_sc26198disableintrs(struct stlport *portp);
499 static void stl_sc26198sendbreak(struct stlport *portp, int len);
500 static void stl_sc26198flowctrl(struct stlport *portp, int state);
501 static void stl_sc26198sendflow(struct stlport *portp, int state);
502 static void stl_sc26198flush(struct stlport *portp);
503 static int stl_sc26198datastate(struct stlport *portp);
504 static void stl_sc26198wait(struct stlport *portp);
505 static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty);
506 static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase);
507 static void stl_sc26198txisr(struct stlport *port);
508 static void stl_sc26198rxisr(struct stlport *port, unsigned int iack);
509 static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch);
510 static void stl_sc26198rxbadchars(struct stlport *portp);
511 static void stl_sc26198otherisr(struct stlport *port, unsigned int iack);
513 /*****************************************************************************/
516 * Generic UART support structure.
518 typedef struct uart {
519 int (*panelinit)(struct stlbrd *brdp, struct stlpanel *panelp);
520 void (*portinit)(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
521 void (*setport)(struct stlport *portp, struct ktermios *tiosp);
522 int (*getsignals)(struct stlport *portp);
523 void (*setsignals)(struct stlport *portp, int dtr, int rts);
524 void (*enablerxtx)(struct stlport *portp, int rx, int tx);
525 void (*startrxtx)(struct stlport *portp, int rx, int tx);
526 void (*disableintrs)(struct stlport *portp);
527 void (*sendbreak)(struct stlport *portp, int len);
528 void (*flowctrl)(struct stlport *portp, int state);
529 void (*sendflow)(struct stlport *portp, int state);
530 void (*flush)(struct stlport *portp);
531 int (*datastate)(struct stlport *portp);
532 void (*intr)(struct stlpanel *panelp, unsigned int iobase);
536 * Define some macros to make calling these functions nice and clean.
538 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
539 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
540 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
541 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
542 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
543 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
544 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
545 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
546 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
547 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
548 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
549 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
550 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
552 /*****************************************************************************/
555 * CD1400 UART specific data initialization.
557 static uart_t stl_cd1400uart = {
561 stl_cd1400getsignals,
562 stl_cd1400setsignals,
563 stl_cd1400enablerxtx,
565 stl_cd1400disableintrs,
575 * Define the offsets within the register bank of a cd1400 based panel.
576 * These io address offsets are common to the EasyIO board as well.
584 #define EREG_BANKSIZE 8
586 #define CD1400_CLK 25000000
587 #define CD1400_CLK8M 20000000
590 * Define the cd1400 baud rate clocks. These are used when calculating
591 * what clock and divisor to use for the required baud rate. Also
592 * define the maximum baud rate allowed, and the default base baud.
594 static int stl_cd1400clkdivs[] = {
595 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
598 /*****************************************************************************/
601 * SC26198 UART specific data initization.
603 static uart_t stl_sc26198uart = {
604 stl_sc26198panelinit,
607 stl_sc26198getsignals,
608 stl_sc26198setsignals,
609 stl_sc26198enablerxtx,
610 stl_sc26198startrxtx,
611 stl_sc26198disableintrs,
612 stl_sc26198sendbreak,
616 stl_sc26198datastate,
621 * Define the offsets within the register bank of a sc26198 based panel.
629 #define XP_BANKSIZE 4
632 * Define the sc26198 baud rate table. Offsets within the table
633 * represent the actual baud rate selector of sc26198 registers.
635 static unsigned int sc26198_baudtable[] = {
636 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
637 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
638 230400, 460800, 921600
641 #define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
643 /*****************************************************************************/
646 * Define the driver info for a user level control device. Used mainly
647 * to get at port stats - only not using the port device itself.
649 static const struct file_operations stl_fsiomem = {
650 .owner = THIS_MODULE,
651 .ioctl = stl_memioctl,
654 static struct class *stallion_class;
657 * Check for any arguments passed in on the module load command line.
660 /*****************************************************************************/
663 * Convert an ascii string number into an unsigned long.
666 static unsigned long stl_atol(char *str)
674 if ((*sp == '0') && (*(sp+1) == 'x')) {
677 } else if (*sp == '0') {
684 for (; (*sp != 0); sp++) {
685 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
686 if ((c < 0) || (c >= base)) {
687 printk("STALLION: invalid argument %s\n", str);
691 val = (val * base) + c;
696 /*****************************************************************************/
699 * Parse the supplied argument string, into the board conf struct.
702 static int __init stl_parsebrd(struct stlconf *confp, char **argp)
707 pr_debug("stl_parsebrd(confp=%p,argp=%p)\n", confp, argp);
709 if ((argp[0] == NULL) || (*argp[0] == 0))
712 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
715 for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++) {
716 if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
719 if (i == ARRAY_SIZE(stl_brdstr)) {
720 printk("STALLION: unknown board name, %s?\n", argp[0]);
724 confp->brdtype = stl_brdstr[i].type;
727 if ((argp[i] != NULL) && (*argp[i] != 0))
728 confp->ioaddr1 = stl_atol(argp[i]);
730 if (confp->brdtype == BRD_ECH) {
731 if ((argp[i] != NULL) && (*argp[i] != 0))
732 confp->ioaddr2 = stl_atol(argp[i]);
735 if ((argp[i] != NULL) && (*argp[i] != 0))
736 confp->irq = stl_atol(argp[i]);
740 /*****************************************************************************/
743 * Allocate a new board structure. Fill out the basic info in it.
746 static struct stlbrd *stl_allocbrd(void)
750 brdp = kzalloc(sizeof(struct stlbrd), GFP_KERNEL);
752 printk("STALLION: failed to allocate memory (size=%Zd)\n",
753 sizeof(struct stlbrd));
757 brdp->magic = STL_BOARDMAGIC;
761 static void __init stl_argbrds(void)
767 pr_debug("stl_argbrds()\n");
769 for (i = stl_nrbrds; (i < stl_nargs); i++) {
770 memset(&conf, 0, sizeof(conf));
771 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
773 if ((brdp = stl_allocbrd()) == NULL)
777 brdp->brdtype = conf.brdtype;
778 brdp->ioaddr1 = conf.ioaddr1;
779 brdp->ioaddr2 = conf.ioaddr2;
780 brdp->irq = conf.irq;
781 brdp->irqtype = conf.irqtype;
786 /*****************************************************************************/
788 static int stl_open(struct tty_struct *tty, struct file *filp)
790 struct stlport *portp;
792 unsigned int minordev;
793 int brdnr, panelnr, portnr, rc;
795 pr_debug("stl_open(tty=%p,filp=%p): device=%s\n", tty, filp, tty->name);
797 minordev = tty->index;
798 brdnr = MINOR2BRD(minordev);
799 if (brdnr >= stl_nrbrds)
801 brdp = stl_brds[brdnr];
804 minordev = MINOR2PORT(minordev);
805 for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
806 if (brdp->panels[panelnr] == NULL)
808 if (minordev < brdp->panels[panelnr]->nrports) {
812 minordev -= brdp->panels[panelnr]->nrports;
817 portp = brdp->panels[panelnr]->ports[portnr];
822 * On the first open of the device setup the port hardware, and
823 * initialize the per port data structure.
826 tty->driver_data = portp;
829 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
830 if (!portp->tx.buf) {
831 portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
834 portp->tx.head = portp->tx.buf;
835 portp->tx.tail = portp->tx.buf;
837 stl_setport(portp, tty->termios);
838 portp->sigs = stl_getsignals(portp);
839 stl_setsignals(portp, 1, 1);
840 stl_enablerxtx(portp, 1, 1);
841 stl_startrxtx(portp, 1, 0);
842 clear_bit(TTY_IO_ERROR, &tty->flags);
843 portp->flags |= ASYNC_INITIALIZED;
847 * Check if this port is in the middle of closing. If so then wait
848 * until it is closed then return error status, based on flag settings.
849 * The sleep here does not need interrupt protection since the wakeup
850 * for it is done with the same context.
852 if (portp->flags & ASYNC_CLOSING) {
853 interruptible_sleep_on(&portp->close_wait);
854 if (portp->flags & ASYNC_HUP_NOTIFY)
860 * Based on type of open being done check if it can overlap with any
861 * previous opens still in effect. If we are a normal serial device
862 * then also we might have to wait for carrier.
864 if (!(filp->f_flags & O_NONBLOCK)) {
865 if ((rc = stl_waitcarrier(portp, filp)) != 0)
868 portp->flags |= ASYNC_NORMAL_ACTIVE;
873 /*****************************************************************************/
876 * Possibly need to wait for carrier (DCD signal) to come high. Say
877 * maybe because if we are clocal then we don't need to wait...
880 static int stl_waitcarrier(struct stlport *portp, struct file *filp)
885 pr_debug("stl_waitcarrier(portp=%p,filp=%p)\n", portp, filp);
890 spin_lock_irqsave(&stallion_lock, flags);
892 if (portp->tty->termios->c_cflag & CLOCAL)
895 portp->openwaitcnt++;
896 if (! tty_hung_up_p(filp))
900 /* Takes brd_lock internally */
901 stl_setsignals(portp, 1, 1);
902 if (tty_hung_up_p(filp) ||
903 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
904 if (portp->flags & ASYNC_HUP_NOTIFY)
910 if (((portp->flags & ASYNC_CLOSING) == 0) &&
911 (doclocal || (portp->sigs & TIOCM_CD))) {
914 if (signal_pending(current)) {
919 interruptible_sleep_on(&portp->open_wait);
922 if (! tty_hung_up_p(filp))
924 portp->openwaitcnt--;
925 spin_unlock_irqrestore(&stallion_lock, flags);
930 /*****************************************************************************/
932 static void stl_flushbuffer(struct tty_struct *tty)
934 struct stlport *portp;
936 pr_debug("stl_flushbuffer(tty=%p)\n", tty);
940 portp = tty->driver_data;
948 /*****************************************************************************/
950 static void stl_waituntilsent(struct tty_struct *tty, int timeout)
952 struct stlport *portp;
955 pr_debug("stl_waituntilsent(tty=%p,timeout=%d)\n", tty, timeout);
959 portp = tty->driver_data;
965 tend = jiffies + timeout;
967 while (stl_datastate(portp)) {
968 if (signal_pending(current))
970 msleep_interruptible(20);
971 if (time_after_eq(jiffies, tend))
976 /*****************************************************************************/
978 static void stl_close(struct tty_struct *tty, struct file *filp)
980 struct stlport *portp;
983 pr_debug("stl_close(tty=%p,filp=%p)\n", tty, filp);
985 portp = tty->driver_data;
989 spin_lock_irqsave(&stallion_lock, flags);
990 if (tty_hung_up_p(filp)) {
991 spin_unlock_irqrestore(&stallion_lock, flags);
994 if ((tty->count == 1) && (portp->refcount != 1))
996 if (portp->refcount-- > 1) {
997 spin_unlock_irqrestore(&stallion_lock, flags);
1001 portp->refcount = 0;
1002 portp->flags |= ASYNC_CLOSING;
1005 * May want to wait for any data to drain before closing. The BUSY
1006 * flag keeps track of whether we are still sending or not - it is
1007 * very accurate for the cd1400, not quite so for the sc26198.
1008 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1012 spin_unlock_irqrestore(&stallion_lock, flags);
1014 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1015 tty_wait_until_sent(tty, portp->closing_wait);
1016 stl_waituntilsent(tty, (HZ / 2));
1019 spin_lock_irqsave(&stallion_lock, flags);
1020 portp->flags &= ~ASYNC_INITIALIZED;
1021 spin_unlock_irqrestore(&stallion_lock, flags);
1023 stl_disableintrs(portp);
1024 if (tty->termios->c_cflag & HUPCL)
1025 stl_setsignals(portp, 0, 0);
1026 stl_enablerxtx(portp, 0, 0);
1027 stl_flushbuffer(tty);
1029 if (portp->tx.buf != NULL) {
1030 kfree(portp->tx.buf);
1031 portp->tx.buf = NULL;
1032 portp->tx.head = NULL;
1033 portp->tx.tail = NULL;
1035 set_bit(TTY_IO_ERROR, &tty->flags);
1036 tty_ldisc_flush(tty);
1041 if (portp->openwaitcnt) {
1042 if (portp->close_delay)
1043 msleep_interruptible(jiffies_to_msecs(portp->close_delay));
1044 wake_up_interruptible(&portp->open_wait);
1047 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1048 wake_up_interruptible(&portp->close_wait);
1051 /*****************************************************************************/
1054 * Write routine. Take data and stuff it in to the TX ring queue.
1055 * If transmit interrupts are not running then start them.
1058 static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
1060 struct stlport *portp;
1061 unsigned int len, stlen;
1062 unsigned char *chbuf;
1065 pr_debug("stl_write(tty=%p,buf=%p,count=%d)\n", tty, buf, count);
1067 portp = tty->driver_data;
1070 if (portp->tx.buf == NULL)
1074 * If copying direct from user space we must cater for page faults,
1075 * causing us to "sleep" here for a while. To handle this copy in all
1076 * the data we need now, into a local buffer. Then when we got it all
1077 * copy it into the TX buffer.
1079 chbuf = (unsigned char *) buf;
1081 head = portp->tx.head;
1082 tail = portp->tx.tail;
1084 len = STL_TXBUFSIZE - (head - tail) - 1;
1085 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
1087 len = tail - head - 1;
1091 len = MIN(len, count);
1094 stlen = MIN(len, stlen);
1095 memcpy(head, chbuf, stlen);
1100 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
1101 head = portp->tx.buf;
1102 stlen = tail - head;
1105 portp->tx.head = head;
1107 clear_bit(ASYI_TXLOW, &portp->istate);
1108 stl_startrxtx(portp, -1, 1);
1113 /*****************************************************************************/
1115 static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1117 struct stlport *portp;
1121 pr_debug("stl_putchar(tty=%p,ch=%x)\n", tty, ch);
1125 portp = tty->driver_data;
1128 if (portp->tx.buf == NULL)
1131 head = portp->tx.head;
1132 tail = portp->tx.tail;
1134 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
1139 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
1140 head = portp->tx.buf;
1142 portp->tx.head = head;
1145 /*****************************************************************************/
1148 * If there are any characters in the buffer then make sure that TX
1149 * interrupts are on and get'em out. Normally used after the putchar
1150 * routine has been called.
1153 static void stl_flushchars(struct tty_struct *tty)
1155 struct stlport *portp;
1157 pr_debug("stl_flushchars(tty=%p)\n", tty);
1161 portp = tty->driver_data;
1164 if (portp->tx.buf == NULL)
1167 stl_startrxtx(portp, -1, 1);
1170 /*****************************************************************************/
1172 static int stl_writeroom(struct tty_struct *tty)
1174 struct stlport *portp;
1177 pr_debug("stl_writeroom(tty=%p)\n", tty);
1181 portp = tty->driver_data;
1184 if (portp->tx.buf == NULL)
1187 head = portp->tx.head;
1188 tail = portp->tx.tail;
1189 return ((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
1192 /*****************************************************************************/
1195 * Return number of chars in the TX buffer. Normally we would just
1196 * calculate the number of chars in the buffer and return that, but if
1197 * the buffer is empty and TX interrupts are still on then we return
1198 * that the buffer still has 1 char in it. This way whoever called us
1199 * will not think that ALL chars have drained - since the UART still
1200 * must have some chars in it (we are busy after all).
1203 static int stl_charsinbuffer(struct tty_struct *tty)
1205 struct stlport *portp;
1209 pr_debug("stl_charsinbuffer(tty=%p)\n", tty);
1213 portp = tty->driver_data;
1216 if (portp->tx.buf == NULL)
1219 head = portp->tx.head;
1220 tail = portp->tx.tail;
1221 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1222 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1227 /*****************************************************************************/
1230 * Generate the serial struct info.
1233 static int stl_getserial(struct stlport *portp, struct serial_struct __user *sp)
1235 struct serial_struct sio;
1236 struct stlbrd *brdp;
1238 pr_debug("stl_getserial(portp=%p,sp=%p)\n", portp, sp);
1240 memset(&sio, 0, sizeof(struct serial_struct));
1241 sio.line = portp->portnr;
1242 sio.port = portp->ioaddr;
1243 sio.flags = portp->flags;
1244 sio.baud_base = portp->baud_base;
1245 sio.close_delay = portp->close_delay;
1246 sio.closing_wait = portp->closing_wait;
1247 sio.custom_divisor = portp->custom_divisor;
1249 if (portp->uartp == &stl_cd1400uart) {
1250 sio.type = PORT_CIRRUS;
1251 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1253 sio.type = PORT_UNKNOWN;
1254 sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1257 brdp = stl_brds[portp->brdnr];
1259 sio.irq = brdp->irq;
1261 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
1264 /*****************************************************************************/
1267 * Set port according to the serial struct info.
1268 * At this point we do not do any auto-configure stuff, so we will
1269 * just quietly ignore any requests to change irq, etc.
1272 static int stl_setserial(struct stlport *portp, struct serial_struct __user *sp)
1274 struct serial_struct sio;
1276 pr_debug("stl_setserial(portp=%p,sp=%p)\n", portp, sp);
1278 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1280 if (!capable(CAP_SYS_ADMIN)) {
1281 if ((sio.baud_base != portp->baud_base) ||
1282 (sio.close_delay != portp->close_delay) ||
1283 ((sio.flags & ~ASYNC_USR_MASK) !=
1284 (portp->flags & ~ASYNC_USR_MASK)))
1288 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1289 (sio.flags & ASYNC_USR_MASK);
1290 portp->baud_base = sio.baud_base;
1291 portp->close_delay = sio.close_delay;
1292 portp->closing_wait = sio.closing_wait;
1293 portp->custom_divisor = sio.custom_divisor;
1294 stl_setport(portp, portp->tty->termios);
1298 /*****************************************************************************/
1300 static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1302 struct stlport *portp;
1306 portp = tty->driver_data;
1309 if (tty->flags & (1 << TTY_IO_ERROR))
1312 return stl_getsignals(portp);
1315 static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1316 unsigned int set, unsigned int clear)
1318 struct stlport *portp;
1319 int rts = -1, dtr = -1;
1323 portp = tty->driver_data;
1326 if (tty->flags & (1 << TTY_IO_ERROR))
1329 if (set & TIOCM_RTS)
1331 if (set & TIOCM_DTR)
1333 if (clear & TIOCM_RTS)
1335 if (clear & TIOCM_DTR)
1338 stl_setsignals(portp, dtr, rts);
1342 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1344 struct stlport *portp;
1347 void __user *argp = (void __user *)arg;
1349 pr_debug("stl_ioctl(tty=%p,file=%p,cmd=%x,arg=%lx)\n", tty, file, cmd,
1354 portp = tty->driver_data;
1358 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1359 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1360 if (tty->flags & (1 << TTY_IO_ERROR))
1368 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1369 (unsigned __user *) argp);
1372 if (get_user(ival, (unsigned int __user *) arg))
1374 tty->termios->c_cflag =
1375 (tty->termios->c_cflag & ~CLOCAL) |
1376 (ival ? CLOCAL : 0);
1379 rc = stl_getserial(portp, argp);
1382 rc = stl_setserial(portp, argp);
1384 case COM_GETPORTSTATS:
1385 rc = stl_getportstats(portp, argp);
1387 case COM_CLRPORTSTATS:
1388 rc = stl_clrportstats(portp, argp);
1394 case TIOCSERGSTRUCT:
1395 case TIOCSERGETMULTI:
1396 case TIOCSERSETMULTI:
1405 /*****************************************************************************/
1408 * Start the transmitter again. Just turn TX interrupts back on.
1411 static void stl_start(struct tty_struct *tty)
1413 struct stlport *portp;
1415 pr_debug("stl_start(tty=%p)\n", tty);
1419 portp = tty->driver_data;
1422 stl_startrxtx(portp, -1, 1);
1425 /*****************************************************************************/
1427 static void stl_settermios(struct tty_struct *tty, struct ktermios *old)
1429 struct stlport *portp;
1430 struct ktermios *tiosp;
1432 pr_debug("stl_settermios(tty=%p,old=%p)\n", tty, old);
1436 portp = tty->driver_data;
1440 tiosp = tty->termios;
1441 if ((tiosp->c_cflag == old->c_cflag) &&
1442 (tiosp->c_iflag == old->c_iflag))
1445 stl_setport(portp, tiosp);
1446 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1448 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1449 tty->hw_stopped = 0;
1452 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1453 wake_up_interruptible(&portp->open_wait);
1456 /*****************************************************************************/
1459 * Attempt to flow control who ever is sending us data. Based on termios
1460 * settings use software or/and hardware flow control.
1463 static void stl_throttle(struct tty_struct *tty)
1465 struct stlport *portp;
1467 pr_debug("stl_throttle(tty=%p)\n", tty);
1471 portp = tty->driver_data;
1474 stl_flowctrl(portp, 0);
1477 /*****************************************************************************/
1480 * Unflow control the device sending us data...
1483 static void stl_unthrottle(struct tty_struct *tty)
1485 struct stlport *portp;
1487 pr_debug("stl_unthrottle(tty=%p)\n", tty);
1491 portp = tty->driver_data;
1494 stl_flowctrl(portp, 1);
1497 /*****************************************************************************/
1500 * Stop the transmitter. Basically to do this we will just turn TX
1504 static void stl_stop(struct tty_struct *tty)
1506 struct stlport *portp;
1508 pr_debug("stl_stop(tty=%p)\n", tty);
1512 portp = tty->driver_data;
1515 stl_startrxtx(portp, -1, 0);
1518 /*****************************************************************************/
1521 * Hangup this port. This is pretty much like closing the port, only
1522 * a little more brutal. No waiting for data to drain. Shutdown the
1523 * port and maybe drop signals.
1526 static void stl_hangup(struct tty_struct *tty)
1528 struct stlport *portp;
1530 pr_debug("stl_hangup(tty=%p)\n", tty);
1534 portp = tty->driver_data;
1538 portp->flags &= ~ASYNC_INITIALIZED;
1539 stl_disableintrs(portp);
1540 if (tty->termios->c_cflag & HUPCL)
1541 stl_setsignals(portp, 0, 0);
1542 stl_enablerxtx(portp, 0, 0);
1543 stl_flushbuffer(tty);
1545 set_bit(TTY_IO_ERROR, &tty->flags);
1546 if (portp->tx.buf != NULL) {
1547 kfree(portp->tx.buf);
1548 portp->tx.buf = NULL;
1549 portp->tx.head = NULL;
1550 portp->tx.tail = NULL;
1553 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1554 portp->refcount = 0;
1555 wake_up_interruptible(&portp->open_wait);
1558 /*****************************************************************************/
1560 static void stl_breakctl(struct tty_struct *tty, int state)
1562 struct stlport *portp;
1564 pr_debug("stl_breakctl(tty=%p,state=%d)\n", tty, state);
1568 portp = tty->driver_data;
1572 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1575 /*****************************************************************************/
1577 static void stl_sendxchar(struct tty_struct *tty, char ch)
1579 struct stlport *portp;
1581 pr_debug("stl_sendxchar(tty=%p,ch=%x)\n", tty, ch);
1585 portp = tty->driver_data;
1589 if (ch == STOP_CHAR(tty))
1590 stl_sendflow(portp, 0);
1591 else if (ch == START_CHAR(tty))
1592 stl_sendflow(portp, 1);
1594 stl_putchar(tty, ch);
1597 /*****************************************************************************/
1602 * Format info for a specified port. The line is deliberately limited
1603 * to 80 characters. (If it is too long it will be truncated, if too
1604 * short then padded with spaces).
1607 static int stl_portinfo(struct stlport *portp, int portnr, char *pos)
1613 sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
1614 portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
1615 (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
1617 if (portp->stats.rxframing)
1618 sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
1619 if (portp->stats.rxparity)
1620 sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
1621 if (portp->stats.rxbreaks)
1622 sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
1623 if (portp->stats.rxoverrun)
1624 sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
1626 sigs = stl_getsignals(portp);
1627 cnt = sprintf(sp, "%s%s%s%s%s ",
1628 (sigs & TIOCM_RTS) ? "|RTS" : "",
1629 (sigs & TIOCM_CTS) ? "|CTS" : "",
1630 (sigs & TIOCM_DTR) ? "|DTR" : "",
1631 (sigs & TIOCM_CD) ? "|DCD" : "",
1632 (sigs & TIOCM_DSR) ? "|DSR" : "");
1636 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
1639 pos[(MAXLINE - 2)] = '+';
1640 pos[(MAXLINE - 1)] = '\n';
1645 /*****************************************************************************/
1648 * Port info, read from the /proc file system.
1651 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
1653 struct stlbrd *brdp;
1654 struct stlpanel *panelp;
1655 struct stlport *portp;
1656 int brdnr, panelnr, portnr, totalport;
1660 pr_debug("stl_readproc(page=%p,start=%p,off=%lx,count=%d,eof=%p,"
1661 "data=%p\n", page, start, off, count, eof, data);
1668 pos += sprintf(pos, "%s: version %s", stl_drvtitle,
1670 while (pos < (page + MAXLINE - 1))
1677 * We scan through for each board, panel and port. The offset is
1678 * calculated on the fly, and irrelevant ports are skipped.
1680 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1681 brdp = stl_brds[brdnr];
1684 if (brdp->state == 0)
1687 maxoff = curoff + (brdp->nrports * MAXLINE);
1688 if (off >= maxoff) {
1693 totalport = brdnr * STL_MAXPORTS;
1694 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1695 panelp = brdp->panels[panelnr];
1699 maxoff = curoff + (panelp->nrports * MAXLINE);
1700 if (off >= maxoff) {
1702 totalport += panelp->nrports;
1706 for (portnr = 0; (portnr < panelp->nrports); portnr++,
1708 portp = panelp->ports[portnr];
1711 if (off >= (curoff += MAXLINE))
1713 if ((pos - page + MAXLINE) > count)
1715 pos += stl_portinfo(portp, totalport, pos);
1724 return (pos - page);
1727 /*****************************************************************************/
1730 * All board interrupts are vectored through here first. This code then
1731 * calls off to the approrpriate board interrupt handlers.
1734 static irqreturn_t stl_intr(int irq, void *dev_id)
1736 struct stlbrd *brdp = dev_id;
1738 pr_debug("stl_intr(brdp=%p,irq=%d)\n", brdp, irq);
1740 return IRQ_RETVAL((* brdp->isr)(brdp));
1743 /*****************************************************************************/
1746 * Interrupt service routine for EasyIO board types.
1749 static int stl_eiointr(struct stlbrd *brdp)
1751 struct stlpanel *panelp;
1752 unsigned int iobase;
1755 spin_lock(&brd_lock);
1756 panelp = brdp->panels[0];
1757 iobase = panelp->iobase;
1758 while (inb(brdp->iostatus) & EIO_INTRPEND) {
1760 (* panelp->isr)(panelp, iobase);
1762 spin_unlock(&brd_lock);
1766 /*****************************************************************************/
1769 * Interrupt service routine for ECH-AT board types.
1772 static int stl_echatintr(struct stlbrd *brdp)
1774 struct stlpanel *panelp;
1775 unsigned int ioaddr;
1779 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
1781 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1783 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1784 ioaddr = brdp->bnkstataddr[bnknr];
1785 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1786 panelp = brdp->bnk2panel[bnknr];
1787 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1792 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
1797 /*****************************************************************************/
1800 * Interrupt service routine for ECH-MCA board types.
1803 static int stl_echmcaintr(struct stlbrd *brdp)
1805 struct stlpanel *panelp;
1806 unsigned int ioaddr;
1810 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1812 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1813 ioaddr = brdp->bnkstataddr[bnknr];
1814 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1815 panelp = brdp->bnk2panel[bnknr];
1816 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1823 /*****************************************************************************/
1826 * Interrupt service routine for ECH-PCI board types.
1829 static int stl_echpciintr(struct stlbrd *brdp)
1831 struct stlpanel *panelp;
1832 unsigned int ioaddr;
1838 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1839 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
1840 ioaddr = brdp->bnkstataddr[bnknr];
1841 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1842 panelp = brdp->bnk2panel[bnknr];
1843 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1854 /*****************************************************************************/
1857 * Interrupt service routine for ECH-8/64-PCI board types.
1860 static int stl_echpci64intr(struct stlbrd *brdp)
1862 struct stlpanel *panelp;
1863 unsigned int ioaddr;
1867 while (inb(brdp->ioctrl) & 0x1) {
1869 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1870 ioaddr = brdp->bnkstataddr[bnknr];
1871 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1872 panelp = brdp->bnk2panel[bnknr];
1873 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1881 /*****************************************************************************/
1884 * Service an off-level request for some channel.
1886 static void stl_offintr(struct work_struct *work)
1888 struct stlport *portp = container_of(work, struct stlport, tqueue);
1889 struct tty_struct *tty;
1890 unsigned int oldsigs;
1892 pr_debug("stl_offintr(portp=%p)\n", portp);
1902 if (test_bit(ASYI_TXLOW, &portp->istate)) {
1905 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
1906 clear_bit(ASYI_DCDCHANGE, &portp->istate);
1907 oldsigs = portp->sigs;
1908 portp->sigs = stl_getsignals(portp);
1909 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
1910 wake_up_interruptible(&portp->open_wait);
1911 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
1912 if (portp->flags & ASYNC_CHECK_CD)
1913 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
1919 /*****************************************************************************/
1922 * Initialize all the ports on a panel.
1925 static int __init stl_initports(struct stlbrd *brdp, struct stlpanel *panelp)
1927 struct stlport *portp;
1930 pr_debug("stl_initports(brdp=%p,panelp=%p)\n", brdp, panelp);
1932 chipmask = stl_panelinit(brdp, panelp);
1935 * All UART's are initialized (if found!). Now go through and setup
1936 * each ports data structures.
1938 for (i = 0; (i < panelp->nrports); i++) {
1939 portp = kzalloc(sizeof(struct stlport), GFP_KERNEL);
1941 printk("STALLION: failed to allocate memory "
1942 "(size=%Zd)\n", sizeof(struct stlport));
1946 portp->magic = STL_PORTMAGIC;
1948 portp->brdnr = panelp->brdnr;
1949 portp->panelnr = panelp->panelnr;
1950 portp->uartp = panelp->uartp;
1951 portp->clk = brdp->clk;
1952 portp->baud_base = STL_BAUDBASE;
1953 portp->close_delay = STL_CLOSEDELAY;
1954 portp->closing_wait = 30 * HZ;
1955 INIT_WORK(&portp->tqueue, stl_offintr);
1956 init_waitqueue_head(&portp->open_wait);
1957 init_waitqueue_head(&portp->close_wait);
1958 portp->stats.brd = portp->brdnr;
1959 portp->stats.panel = portp->panelnr;
1960 portp->stats.port = portp->portnr;
1961 panelp->ports[i] = portp;
1962 stl_portinit(brdp, panelp, portp);
1968 /*****************************************************************************/
1971 * Try to find and initialize an EasyIO board.
1974 static int __init stl_initeio(struct stlbrd *brdp)
1976 struct stlpanel *panelp;
1977 unsigned int status;
1981 pr_debug("stl_initeio(brdp=%p)\n", brdp);
1983 brdp->ioctrl = brdp->ioaddr1 + 1;
1984 brdp->iostatus = brdp->ioaddr1 + 2;
1986 status = inb(brdp->iostatus);
1987 if ((status & EIO_IDBITMASK) == EIO_MK3)
1991 * Handle board specific stuff now. The real difference is PCI
1994 if (brdp->brdtype == BRD_EASYIOPCI) {
1995 brdp->iosize1 = 0x80;
1996 brdp->iosize2 = 0x80;
1997 name = "serial(EIO-PCI)";
1998 outb(0x41, (brdp->ioaddr2 + 0x4c));
2001 name = "serial(EIO)";
2002 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2003 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2004 printk("STALLION: invalid irq=%d for brd=%d\n",
2005 brdp->irq, brdp->brdnr);
2008 outb((stl_vecmap[brdp->irq] | EIO_0WS |
2009 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
2013 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2014 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2015 "%x conflicts with another device\n", brdp->brdnr,
2020 if (brdp->iosize2 > 0)
2021 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2022 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2023 "address %x conflicts with another device\n",
2024 brdp->brdnr, brdp->ioaddr2);
2025 printk(KERN_WARNING "STALLION: Warning, also "
2026 "releasing board %d I/O address %x \n",
2027 brdp->brdnr, brdp->ioaddr1);
2028 release_region(brdp->ioaddr1, brdp->iosize1);
2033 * Everything looks OK, so let's go ahead and probe for the hardware.
2035 brdp->clk = CD1400_CLK;
2036 brdp->isr = stl_eiointr;
2038 switch (status & EIO_IDBITMASK) {
2040 brdp->clk = CD1400_CLK8M;
2050 switch (status & EIO_BRDMASK) {
2069 * We have verified that the board is actually present, so now we
2070 * can complete the setup.
2073 panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
2075 printk(KERN_WARNING "STALLION: failed to allocate memory "
2076 "(size=%Zd)\n", sizeof(struct stlpanel));
2080 panelp->magic = STL_PANELMAGIC;
2081 panelp->brdnr = brdp->brdnr;
2082 panelp->panelnr = 0;
2083 panelp->nrports = brdp->nrports;
2084 panelp->iobase = brdp->ioaddr1;
2085 panelp->hwid = status;
2086 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2087 panelp->uartp = &stl_sc26198uart;
2088 panelp->isr = stl_sc26198intr;
2090 panelp->uartp = &stl_cd1400uart;
2091 panelp->isr = stl_cd1400eiointr;
2094 brdp->panels[0] = panelp;
2096 brdp->state |= BRD_FOUND;
2097 brdp->hwid = status;
2098 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
2099 printk("STALLION: failed to register interrupt "
2100 "routine for %s irq=%d\n", name, brdp->irq);
2108 /*****************************************************************************/
2111 * Try to find an ECH board and initialize it. This code is capable of
2112 * dealing with all types of ECH board.
2115 static int __init stl_initech(struct stlbrd *brdp)
2117 struct stlpanel *panelp;
2118 unsigned int status, nxtid, ioaddr, conflict;
2119 int panelnr, banknr, i;
2122 pr_debug("stl_initech(brdp=%p)\n", brdp);
2128 * Set up the initial board register contents for boards. This varies a
2129 * bit between the different board types. So we need to handle each
2130 * separately. Also do a check that the supplied IRQ is good.
2132 switch (brdp->brdtype) {
2135 brdp->isr = stl_echatintr;
2136 brdp->ioctrl = brdp->ioaddr1 + 1;
2137 brdp->iostatus = brdp->ioaddr1 + 1;
2138 status = inb(brdp->iostatus);
2139 if ((status & ECH_IDBITMASK) != ECH_ID)
2141 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2142 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2143 printk("STALLION: invalid irq=%d for brd=%d\n",
2144 brdp->irq, brdp->brdnr);
2147 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2148 status |= (stl_vecmap[brdp->irq] << 1);
2149 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2150 brdp->ioctrlval = ECH_INTENABLE |
2151 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2152 for (i = 0; (i < 10); i++)
2153 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2156 name = "serial(EC8/32)";
2157 outb(status, brdp->ioaddr1);
2161 brdp->isr = stl_echmcaintr;
2162 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2163 brdp->iostatus = brdp->ioctrl;
2164 status = inb(brdp->iostatus);
2165 if ((status & ECH_IDBITMASK) != ECH_ID)
2167 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2168 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2169 printk("STALLION: invalid irq=%d for brd=%d\n",
2170 brdp->irq, brdp->brdnr);
2173 outb(ECHMC_BRDRESET, brdp->ioctrl);
2174 outb(ECHMC_INTENABLE, brdp->ioctrl);
2176 name = "serial(EC8/32-MC)";
2180 brdp->isr = stl_echpciintr;
2181 brdp->ioctrl = brdp->ioaddr1 + 2;
2184 name = "serial(EC8/32-PCI)";
2188 brdp->isr = stl_echpci64intr;
2189 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2190 outb(0x43, (brdp->ioaddr1 + 0x4c));
2191 brdp->iosize1 = 0x80;
2192 brdp->iosize2 = 0x80;
2193 name = "serial(EC8/64-PCI)";
2197 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
2203 * Check boards for possible IO address conflicts and return fail status
2204 * if an IO conflict found.
2206 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2207 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2208 "%x conflicts with another device\n", brdp->brdnr,
2213 if (brdp->iosize2 > 0)
2214 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2215 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2216 "address %x conflicts with another device\n",
2217 brdp->brdnr, brdp->ioaddr2);
2218 printk(KERN_WARNING "STALLION: Warning, also "
2219 "releasing board %d I/O address %x \n",
2220 brdp->brdnr, brdp->ioaddr1);
2221 release_region(brdp->ioaddr1, brdp->iosize1);
2226 * Scan through the secondary io address space looking for panels.
2227 * As we find'em allocate and initialize panel structures for each.
2229 brdp->clk = CD1400_CLK;
2230 brdp->hwid = status;
2232 ioaddr = brdp->ioaddr2;
2237 for (i = 0; (i < STL_MAXPANELS); i++) {
2238 if (brdp->brdtype == BRD_ECHPCI) {
2239 outb(nxtid, brdp->ioctrl);
2240 ioaddr = brdp->ioaddr2;
2242 status = inb(ioaddr + ECH_PNLSTATUS);
2243 if ((status & ECH_PNLIDMASK) != nxtid)
2245 panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
2247 printk("STALLION: failed to allocate memory "
2248 "(size=%Zd)\n", sizeof(struct stlpanel));
2251 panelp->magic = STL_PANELMAGIC;
2252 panelp->brdnr = brdp->brdnr;
2253 panelp->panelnr = panelnr;
2254 panelp->iobase = ioaddr;
2255 panelp->pagenr = nxtid;
2256 panelp->hwid = status;
2257 brdp->bnk2panel[banknr] = panelp;
2258 brdp->bnkpageaddr[banknr] = nxtid;
2259 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2261 if (status & ECH_PNLXPID) {
2262 panelp->uartp = &stl_sc26198uart;
2263 panelp->isr = stl_sc26198intr;
2264 if (status & ECH_PNL16PORT) {
2265 panelp->nrports = 16;
2266 brdp->bnk2panel[banknr] = panelp;
2267 brdp->bnkpageaddr[banknr] = nxtid;
2268 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2271 panelp->nrports = 8;
2274 panelp->uartp = &stl_cd1400uart;
2275 panelp->isr = stl_cd1400echintr;
2276 if (status & ECH_PNL16PORT) {
2277 panelp->nrports = 16;
2278 panelp->ackmask = 0x80;
2279 if (brdp->brdtype != BRD_ECHPCI)
2280 ioaddr += EREG_BANKSIZE;
2281 brdp->bnk2panel[banknr] = panelp;
2282 brdp->bnkpageaddr[banknr] = ++nxtid;
2283 brdp->bnkstataddr[banknr++] = ioaddr +
2286 panelp->nrports = 8;
2287 panelp->ackmask = 0xc0;
2292 ioaddr += EREG_BANKSIZE;
2293 brdp->nrports += panelp->nrports;
2294 brdp->panels[panelnr++] = panelp;
2295 if ((brdp->brdtype != BRD_ECHPCI) &&
2296 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
2300 brdp->nrpanels = panelnr;
2301 brdp->nrbnks = banknr;
2302 if (brdp->brdtype == BRD_ECH)
2303 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2305 brdp->state |= BRD_FOUND;
2306 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
2307 printk("STALLION: failed to register interrupt "
2308 "routine for %s irq=%d\n", name, brdp->irq);
2317 /*****************************************************************************/
2320 * Initialize and configure the specified board.
2321 * Scan through all the boards in the configuration and see what we
2322 * can find. Handle EIO and the ECH boards a little differently here
2323 * since the initial search and setup is very different.
2326 static int __init stl_brdinit(struct stlbrd *brdp)
2330 pr_debug("stl_brdinit(brdp=%p)\n", brdp);
2332 switch (brdp->brdtype) {
2344 printk("STALLION: board=%d is unknown board type=%d\n",
2345 brdp->brdnr, brdp->brdtype);
2349 stl_brds[brdp->brdnr] = brdp;
2350 if ((brdp->state & BRD_FOUND) == 0) {
2351 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2352 stl_brdnames[brdp->brdtype], brdp->brdnr,
2353 brdp->ioaddr1, brdp->irq);
2357 for (i = 0; (i < STL_MAXPANELS); i++)
2358 if (brdp->panels[i] != NULL)
2359 stl_initports(brdp, brdp->panels[i]);
2361 printk("STALLION: %s found, board=%d io=%x irq=%d "
2362 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2363 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2368 /*****************************************************************************/
2371 * Find the next available board number that is free.
2374 static int __init stl_getbrdnr(void)
2378 for (i = 0; (i < STL_MAXBRDS); i++) {
2379 if (stl_brds[i] == NULL) {
2380 if (i >= stl_nrbrds)
2388 static void stl_cleanup_panels(struct stlbrd *brdp)
2390 struct stlpanel *panelp;
2391 struct stlport *portp;
2394 for (j = 0; j < STL_MAXPANELS; j++) {
2395 panelp = brdp->panels[j];
2398 for (k = 0; k < STL_PORTSPERPANEL; k++) {
2399 portp = panelp->ports[k];
2402 if (portp->tty != NULL)
2403 stl_hangup(portp->tty);
2404 kfree(portp->tx.buf);
2411 /*****************************************************************************/
2413 * We have a Stallion board. Allocate a board structure and
2414 * initialize it. Read its IO and IRQ resources from PCI
2415 * configuration space.
2418 static int __devinit stl_pciprobe(struct pci_dev *pdev,
2419 const struct pci_device_id *ent)
2421 struct stlbrd *brdp;
2422 unsigned int brdtype = ent->driver_data;
2424 pr_debug("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
2425 pdev->bus->number, pdev->devfn);
2427 if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2430 dev_info(&pdev->dev, "please, report this to LKML: %x/%x/%x\n",
2431 pdev->vendor, pdev->device, pdev->class);
2433 if (pci_enable_device(pdev))
2435 if ((brdp = stl_allocbrd()) == NULL)
2437 if ((brdp->brdnr = stl_getbrdnr()) < 0) {
2438 printk("STALLION: too many boards found, "
2439 "maximum supported %d\n", STL_MAXBRDS);
2442 brdp->brdtype = brdtype;
2445 * Different Stallion boards use the BAR registers in different ways,
2446 * so set up io addresses based on board type.
2448 pr_debug("%s(%d): BAR[]=%Lx,%Lx,%Lx,%Lx IRQ=%x\n", __FILE__, __LINE__,
2449 pci_resource_start(pdev, 0), pci_resource_start(pdev, 1),
2450 pci_resource_start(pdev, 2), pci_resource_start(pdev, 3), pdev->irq);
2453 * We have all resources from the board, so let's setup the actual
2454 * board structure now.
2458 brdp->ioaddr2 = pci_resource_start(pdev, 0);
2459 brdp->ioaddr1 = pci_resource_start(pdev, 1);
2462 brdp->ioaddr2 = pci_resource_start(pdev, 2);
2463 brdp->ioaddr1 = pci_resource_start(pdev, 1);
2466 brdp->ioaddr1 = pci_resource_start(pdev, 2);
2467 brdp->ioaddr2 = pci_resource_start(pdev, 1);
2470 printk("STALLION: unknown PCI board type=%d\n", brdtype);
2474 brdp->irq = pdev->irq;
2477 pci_set_drvdata(pdev, brdp);
2482 static void __devexit stl_pciremove(struct pci_dev *pdev)
2484 struct stlbrd *brdp = pci_get_drvdata(pdev);
2486 free_irq(brdp->irq, brdp);
2488 stl_cleanup_panels(brdp);
2490 release_region(brdp->ioaddr1, brdp->iosize1);
2491 if (brdp->iosize2 > 0)
2492 release_region(brdp->ioaddr2, brdp->iosize2);
2494 stl_brds[brdp->brdnr] = NULL;
2498 static struct pci_driver stl_pcidriver = {
2500 .id_table = stl_pcibrds,
2501 .probe = stl_pciprobe,
2502 .remove = __devexit_p(stl_pciremove)
2505 /*****************************************************************************/
2508 * Scan through all the boards in the configuration and see what we
2509 * can find. Handle EIO and the ECH boards a little differently here
2510 * since the initial search and setup is too different.
2513 static int __init stl_initbrds(void)
2515 struct stlbrd *brdp;
2516 struct stlconf *confp;
2519 pr_debug("stl_initbrds()\n");
2521 if (stl_nrbrds > STL_MAXBRDS) {
2522 printk("STALLION: too many boards in configuration table, "
2523 "truncating to %d\n", STL_MAXBRDS);
2524 stl_nrbrds = STL_MAXBRDS;
2528 * Firstly scan the list of static boards configured. Allocate
2529 * resources and initialize the boards as found.
2531 for (i = 0; (i < stl_nrbrds); i++) {
2532 confp = &stl_brdconf[i];
2533 stl_parsebrd(confp, stl_brdsp[i]);
2534 if ((brdp = stl_allocbrd()) == NULL)
2537 brdp->brdtype = confp->brdtype;
2538 brdp->ioaddr1 = confp->ioaddr1;
2539 brdp->ioaddr2 = confp->ioaddr2;
2540 brdp->irq = confp->irq;
2541 brdp->irqtype = confp->irqtype;
2546 * Find any dynamically supported boards. That is via module load
2547 * line options or auto-detected on the PCI bus.
2554 /*****************************************************************************/
2557 * Return the board stats structure to user app.
2560 static int stl_getbrdstats(combrd_t __user *bp)
2562 struct stlbrd *brdp;
2563 struct stlpanel *panelp;
2566 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2568 if (stl_brdstats.brd >= STL_MAXBRDS)
2570 brdp = stl_brds[stl_brdstats.brd];
2574 memset(&stl_brdstats, 0, sizeof(combrd_t));
2575 stl_brdstats.brd = brdp->brdnr;
2576 stl_brdstats.type = brdp->brdtype;
2577 stl_brdstats.hwid = brdp->hwid;
2578 stl_brdstats.state = brdp->state;
2579 stl_brdstats.ioaddr = brdp->ioaddr1;
2580 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2581 stl_brdstats.irq = brdp->irq;
2582 stl_brdstats.nrpanels = brdp->nrpanels;
2583 stl_brdstats.nrports = brdp->nrports;
2584 for (i = 0; (i < brdp->nrpanels); i++) {
2585 panelp = brdp->panels[i];
2586 stl_brdstats.panels[i].panel = i;
2587 stl_brdstats.panels[i].hwid = panelp->hwid;
2588 stl_brdstats.panels[i].nrports = panelp->nrports;
2591 return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
2594 /*****************************************************************************/
2597 * Resolve the referenced port number into a port struct pointer.
2600 static struct stlport *stl_getport(int brdnr, int panelnr, int portnr)
2602 struct stlbrd *brdp;
2603 struct stlpanel *panelp;
2605 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2607 brdp = stl_brds[brdnr];
2610 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2612 panelp = brdp->panels[panelnr];
2615 if ((portnr < 0) || (portnr >= panelp->nrports))
2617 return(panelp->ports[portnr]);
2620 /*****************************************************************************/
2623 * Return the port stats structure to user app. A NULL port struct
2624 * pointer passed in means that we need to find out from the app
2625 * what port to get stats for (used through board control device).
2628 static int stl_getportstats(struct stlport *portp, comstats_t __user *cp)
2630 unsigned char *head, *tail;
2631 unsigned long flags;
2634 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2636 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2642 portp->stats.state = portp->istate;
2643 portp->stats.flags = portp->flags;
2644 portp->stats.hwid = portp->hwid;
2646 portp->stats.ttystate = 0;
2647 portp->stats.cflags = 0;
2648 portp->stats.iflags = 0;
2649 portp->stats.oflags = 0;
2650 portp->stats.lflags = 0;
2651 portp->stats.rxbuffered = 0;
2653 spin_lock_irqsave(&stallion_lock, flags);
2654 if (portp->tty != NULL) {
2655 if (portp->tty->driver_data == portp) {
2656 portp->stats.ttystate = portp->tty->flags;
2657 /* No longer available as a statistic */
2658 portp->stats.rxbuffered = 1; /*portp->tty->flip.count; */
2659 if (portp->tty->termios != NULL) {
2660 portp->stats.cflags = portp->tty->termios->c_cflag;
2661 portp->stats.iflags = portp->tty->termios->c_iflag;
2662 portp->stats.oflags = portp->tty->termios->c_oflag;
2663 portp->stats.lflags = portp->tty->termios->c_lflag;
2667 spin_unlock_irqrestore(&stallion_lock, flags);
2669 head = portp->tx.head;
2670 tail = portp->tx.tail;
2671 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2672 (STL_TXBUFSIZE - (tail - head)));
2674 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2676 return copy_to_user(cp, &portp->stats,
2677 sizeof(comstats_t)) ? -EFAULT : 0;
2680 /*****************************************************************************/
2683 * Clear the port stats structure. We also return it zeroed out...
2686 static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp)
2689 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2691 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2697 memset(&portp->stats, 0, sizeof(comstats_t));
2698 portp->stats.brd = portp->brdnr;
2699 portp->stats.panel = portp->panelnr;
2700 portp->stats.port = portp->portnr;
2701 return copy_to_user(cp, &portp->stats,
2702 sizeof(comstats_t)) ? -EFAULT : 0;
2705 /*****************************************************************************/
2708 * Return the entire driver ports structure to a user app.
2711 static int stl_getportstruct(struct stlport __user *arg)
2713 struct stlport *portp;
2715 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
2717 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
2718 stl_dummyport.portnr);
2721 return copy_to_user(arg, portp, sizeof(struct stlport)) ? -EFAULT : 0;
2724 /*****************************************************************************/
2727 * Return the entire driver board structure to a user app.
2730 static int stl_getbrdstruct(struct stlbrd __user *arg)
2732 struct stlbrd *brdp;
2734 if (copy_from_user(&stl_dummybrd, arg, sizeof(struct stlbrd)))
2736 if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
2738 brdp = stl_brds[stl_dummybrd.brdnr];
2741 return copy_to_user(arg, brdp, sizeof(struct stlbrd)) ? -EFAULT : 0;
2744 /*****************************************************************************/
2747 * The "staliomem" device is also required to do some special operations
2748 * on the board and/or ports. In this driver it is mostly used for stats
2752 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
2755 void __user *argp = (void __user *)arg;
2757 pr_debug("stl_memioctl(ip=%p,fp=%p,cmd=%x,arg=%lx)\n", ip, fp, cmd,arg);
2760 if (brdnr >= STL_MAXBRDS)
2765 case COM_GETPORTSTATS:
2766 rc = stl_getportstats(NULL, argp);
2768 case COM_CLRPORTSTATS:
2769 rc = stl_clrportstats(NULL, argp);
2771 case COM_GETBRDSTATS:
2772 rc = stl_getbrdstats(argp);
2775 rc = stl_getportstruct(argp);
2778 rc = stl_getbrdstruct(argp);
2788 static const struct tty_operations stl_ops = {
2792 .put_char = stl_putchar,
2793 .flush_chars = stl_flushchars,
2794 .write_room = stl_writeroom,
2795 .chars_in_buffer = stl_charsinbuffer,
2797 .set_termios = stl_settermios,
2798 .throttle = stl_throttle,
2799 .unthrottle = stl_unthrottle,
2802 .hangup = stl_hangup,
2803 .flush_buffer = stl_flushbuffer,
2804 .break_ctl = stl_breakctl,
2805 .wait_until_sent = stl_waituntilsent,
2806 .send_xchar = stl_sendxchar,
2807 .read_proc = stl_readproc,
2808 .tiocmget = stl_tiocmget,
2809 .tiocmset = stl_tiocmset,
2812 /*****************************************************************************/
2813 /* CD1400 HARDWARE FUNCTIONS */
2814 /*****************************************************************************/
2817 * These functions get/set/update the registers of the cd1400 UARTs.
2818 * Access to the cd1400 registers is via an address/data io port pair.
2819 * (Maybe should make this inline...)
2822 static int stl_cd1400getreg(struct stlport *portp, int regnr)
2824 outb((regnr + portp->uartaddr), portp->ioaddr);
2825 return inb(portp->ioaddr + EREG_DATA);
2828 static void stl_cd1400setreg(struct stlport *portp, int regnr, int value)
2830 outb((regnr + portp->uartaddr), portp->ioaddr);
2831 outb(value, portp->ioaddr + EREG_DATA);
2834 static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value)
2836 outb((regnr + portp->uartaddr), portp->ioaddr);
2837 if (inb(portp->ioaddr + EREG_DATA) != value) {
2838 outb(value, portp->ioaddr + EREG_DATA);
2844 /*****************************************************************************/
2847 * Inbitialize the UARTs in a panel. We don't care what sort of board
2848 * these ports are on - since the port io registers are almost
2849 * identical when dealing with ports.
2852 static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
2856 int nrchips, uartaddr, ioaddr;
2857 unsigned long flags;
2859 pr_debug("stl_panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
2861 spin_lock_irqsave(&brd_lock, flags);
2862 BRDENABLE(panelp->brdnr, panelp->pagenr);
2865 * Check that each chip is present and started up OK.
2868 nrchips = panelp->nrports / CD1400_PORTS;
2869 for (i = 0; (i < nrchips); i++) {
2870 if (brdp->brdtype == BRD_ECHPCI) {
2871 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
2872 ioaddr = panelp->iobase;
2874 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
2876 uartaddr = (i & 0x01) ? 0x080 : 0;
2877 outb((GFRCR + uartaddr), ioaddr);
2878 outb(0, (ioaddr + EREG_DATA));
2879 outb((CCR + uartaddr), ioaddr);
2880 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
2881 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
2882 outb((GFRCR + uartaddr), ioaddr);
2883 for (j = 0; (j < CCR_MAXWAIT); j++) {
2884 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
2887 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
2888 printk("STALLION: cd1400 not responding, "
2889 "brd=%d panel=%d chip=%d\n",
2890 panelp->brdnr, panelp->panelnr, i);
2893 chipmask |= (0x1 << i);
2894 outb((PPR + uartaddr), ioaddr);
2895 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
2898 BRDDISABLE(panelp->brdnr);
2899 spin_unlock_irqrestore(&brd_lock, flags);
2903 /*****************************************************************************/
2906 * Initialize hardware specific port registers.
2909 static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
2911 unsigned long flags;
2912 pr_debug("stl_cd1400portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
2915 if ((brdp == NULL) || (panelp == NULL) ||
2919 spin_lock_irqsave(&brd_lock, flags);
2920 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
2921 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
2922 portp->uartaddr = (portp->portnr & 0x04) << 5;
2923 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
2925 BRDENABLE(portp->brdnr, portp->pagenr);
2926 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2927 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
2928 portp->hwid = stl_cd1400getreg(portp, GFRCR);
2929 BRDDISABLE(portp->brdnr);
2930 spin_unlock_irqrestore(&brd_lock, flags);
2933 /*****************************************************************************/
2936 * Wait for the command register to be ready. We will poll this,
2937 * since it won't usually take too long to be ready.
2940 static void stl_cd1400ccrwait(struct stlport *portp)
2944 for (i = 0; (i < CCR_MAXWAIT); i++) {
2945 if (stl_cd1400getreg(portp, CCR) == 0) {
2950 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
2951 portp->portnr, portp->panelnr, portp->brdnr);
2954 /*****************************************************************************/
2957 * Set up the cd1400 registers for a port based on the termios port
2961 static void stl_cd1400setport(struct stlport *portp, struct ktermios *tiosp)
2963 struct stlbrd *brdp;
2964 unsigned long flags;
2965 unsigned int clkdiv, baudrate;
2966 unsigned char cor1, cor2, cor3;
2967 unsigned char cor4, cor5, ccr;
2968 unsigned char srer, sreron, sreroff;
2969 unsigned char mcor1, mcor2, rtpr;
2970 unsigned char clk, div;
2986 brdp = stl_brds[portp->brdnr];
2991 * Set up the RX char ignore mask with those RX error types we
2992 * can ignore. We can get the cd1400 to help us out a little here,
2993 * it will ignore parity errors and breaks for us.
2995 portp->rxignoremsk = 0;
2996 if (tiosp->c_iflag & IGNPAR) {
2997 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
2998 cor1 |= COR1_PARIGNORE;
3000 if (tiosp->c_iflag & IGNBRK) {
3001 portp->rxignoremsk |= ST_BREAK;
3002 cor4 |= COR4_IGNBRK;
3005 portp->rxmarkmsk = ST_OVERRUN;
3006 if (tiosp->c_iflag & (INPCK | PARMRK))
3007 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3008 if (tiosp->c_iflag & BRKINT)
3009 portp->rxmarkmsk |= ST_BREAK;
3012 * Go through the char size, parity and stop bits and set all the
3013 * option register appropriately.
3015 switch (tiosp->c_cflag & CSIZE) {
3030 if (tiosp->c_cflag & CSTOPB)
3035 if (tiosp->c_cflag & PARENB) {
3036 if (tiosp->c_cflag & PARODD)
3037 cor1 |= (COR1_PARENB | COR1_PARODD);
3039 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3041 cor1 |= COR1_PARNONE;
3045 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3046 * space for hardware flow control and the like. This should be set to
3047 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3048 * really be based on VTIME.
3050 cor3 |= FIFO_RXTHRESHOLD;
3054 * Calculate the baud rate timers. For now we will just assume that
3055 * the input and output baud are the same. Could have used a baud
3056 * table here, but this way we can generate virtually any baud rate
3059 baudrate = tiosp->c_cflag & CBAUD;
3060 if (baudrate & CBAUDEX) {
3061 baudrate &= ~CBAUDEX;
3062 if ((baudrate < 1) || (baudrate > 4))
3063 tiosp->c_cflag &= ~CBAUDEX;
3067 baudrate = stl_baudrates[baudrate];
3068 if ((tiosp->c_cflag & CBAUD) == B38400) {
3069 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3071 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3073 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3075 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3077 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3078 baudrate = (portp->baud_base / portp->custom_divisor);
3080 if (baudrate > STL_CD1400MAXBAUD)
3081 baudrate = STL_CD1400MAXBAUD;
3084 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3085 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
3089 div = (unsigned char) clkdiv;
3093 * Check what form of modem signaling is required and set it up.
3095 if ((tiosp->c_cflag & CLOCAL) == 0) {
3098 sreron |= SRER_MODEM;
3099 portp->flags |= ASYNC_CHECK_CD;
3101 portp->flags &= ~ASYNC_CHECK_CD;
3105 * Setup cd1400 enhanced modes if we can. In particular we want to
3106 * handle as much of the flow control as possible automatically. As
3107 * well as saving a few CPU cycles it will also greatly improve flow
3108 * control reliability.
3110 if (tiosp->c_iflag & IXON) {
3113 if (tiosp->c_iflag & IXANY)
3117 if (tiosp->c_cflag & CRTSCTS) {
3119 mcor1 |= FIFO_RTSTHRESHOLD;
3123 * All cd1400 register values calculated so go through and set
3127 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3128 portp->portnr, portp->panelnr, portp->brdnr);
3129 pr_debug(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3130 cor1, cor2, cor3, cor4, cor5);
3131 pr_debug(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3132 mcor1, mcor2, rtpr, sreron, sreroff);
3133 pr_debug(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3134 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3135 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3136 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3138 spin_lock_irqsave(&brd_lock, flags);
3139 BRDENABLE(portp->brdnr, portp->pagenr);
3140 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3141 srer = stl_cd1400getreg(portp, SRER);
3142 stl_cd1400setreg(portp, SRER, 0);
3143 if (stl_cd1400updatereg(portp, COR1, cor1))
3145 if (stl_cd1400updatereg(portp, COR2, cor2))
3147 if (stl_cd1400updatereg(portp, COR3, cor3))
3150 stl_cd1400ccrwait(portp);
3151 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3153 stl_cd1400setreg(portp, COR4, cor4);
3154 stl_cd1400setreg(portp, COR5, cor5);
3155 stl_cd1400setreg(portp, MCOR1, mcor1);
3156 stl_cd1400setreg(portp, MCOR2, mcor2);
3158 stl_cd1400setreg(portp, TCOR, clk);
3159 stl_cd1400setreg(portp, TBPR, div);
3160 stl_cd1400setreg(portp, RCOR, clk);
3161 stl_cd1400setreg(portp, RBPR, div);
3163 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3164 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3165 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3166 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3167 stl_cd1400setreg(portp, RTPR, rtpr);
3168 mcor1 = stl_cd1400getreg(portp, MSVR1);
3169 if (mcor1 & MSVR1_DCD)
3170 portp->sigs |= TIOCM_CD;
3172 portp->sigs &= ~TIOCM_CD;
3173 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3174 BRDDISABLE(portp->brdnr);
3175 spin_unlock_irqrestore(&brd_lock, flags);
3178 /*****************************************************************************/
3181 * Set the state of the DTR and RTS signals.
3184 static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts)
3186 unsigned char msvr1, msvr2;
3187 unsigned long flags;
3189 pr_debug("stl_cd1400setsignals(portp=%p,dtr=%d,rts=%d)\n",
3199 spin_lock_irqsave(&brd_lock, flags);
3200 BRDENABLE(portp->brdnr, portp->pagenr);
3201 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3203 stl_cd1400setreg(portp, MSVR2, msvr2);
3205 stl_cd1400setreg(portp, MSVR1, msvr1);
3206 BRDDISABLE(portp->brdnr);
3207 spin_unlock_irqrestore(&brd_lock, flags);
3210 /*****************************************************************************/
3213 * Return the state of the signals.
3216 static int stl_cd1400getsignals(struct stlport *portp)
3218 unsigned char msvr1, msvr2;
3219 unsigned long flags;
3222 pr_debug("stl_cd1400getsignals(portp=%p)\n", portp);
3224 spin_lock_irqsave(&brd_lock, flags);
3225 BRDENABLE(portp->brdnr, portp->pagenr);
3226 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3227 msvr1 = stl_cd1400getreg(portp, MSVR1);
3228 msvr2 = stl_cd1400getreg(portp, MSVR2);
3229 BRDDISABLE(portp->brdnr);
3230 spin_unlock_irqrestore(&brd_lock, flags);
3233 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3234 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3235 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3236 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3238 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3239 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3246 /*****************************************************************************/
3249 * Enable/Disable the Transmitter and/or Receiver.
3252 static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx)
3255 unsigned long flags;
3257 pr_debug("stl_cd1400enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
3262 ccr |= CCR_TXDISABLE;
3264 ccr |= CCR_TXENABLE;
3266 ccr |= CCR_RXDISABLE;
3268 ccr |= CCR_RXENABLE;
3270 spin_lock_irqsave(&brd_lock, flags);
3271 BRDENABLE(portp->brdnr, portp->pagenr);
3272 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3273 stl_cd1400ccrwait(portp);
3274 stl_cd1400setreg(portp, CCR, ccr);
3275 stl_cd1400ccrwait(portp);
3276 BRDDISABLE(portp->brdnr);
3277 spin_unlock_irqrestore(&brd_lock, flags);
3280 /*****************************************************************************/
3283 * Start/stop the Transmitter and/or Receiver.
3286 static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx)
3288 unsigned char sreron, sreroff;
3289 unsigned long flags;
3291 pr_debug("stl_cd1400startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
3296 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3298 sreron |= SRER_TXDATA;
3300 sreron |= SRER_TXEMPTY;
3302 sreroff |= SRER_RXDATA;
3304 sreron |= SRER_RXDATA;
3306 spin_lock_irqsave(&brd_lock, flags);
3307 BRDENABLE(portp->brdnr, portp->pagenr);
3308 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3309 stl_cd1400setreg(portp, SRER,
3310 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3311 BRDDISABLE(portp->brdnr);
3313 set_bit(ASYI_TXBUSY, &portp->istate);
3314 spin_unlock_irqrestore(&brd_lock, flags);
3317 /*****************************************************************************/
3320 * Disable all interrupts from this port.
3323 static void stl_cd1400disableintrs(struct stlport *portp)
3325 unsigned long flags;
3327 pr_debug("stl_cd1400disableintrs(portp=%p)\n", portp);
3329 spin_lock_irqsave(&brd_lock, flags);
3330 BRDENABLE(portp->brdnr, portp->pagenr);
3331 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3332 stl_cd1400setreg(portp, SRER, 0);
3333 BRDDISABLE(portp->brdnr);
3334 spin_unlock_irqrestore(&brd_lock, flags);
3337 /*****************************************************************************/
3339 static void stl_cd1400sendbreak(struct stlport *portp, int len)
3341 unsigned long flags;
3343 pr_debug("stl_cd1400sendbreak(portp=%p,len=%d)\n", portp, len);
3345 spin_lock_irqsave(&brd_lock, flags);
3346 BRDENABLE(portp->brdnr, portp->pagenr);
3347 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3348 stl_cd1400setreg(portp, SRER,
3349 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3351 BRDDISABLE(portp->brdnr);
3352 portp->brklen = len;
3354 portp->stats.txbreaks++;
3355 spin_unlock_irqrestore(&brd_lock, flags);
3358 /*****************************************************************************/
3361 * Take flow control actions...
3364 static void stl_cd1400flowctrl(struct stlport *portp, int state)
3366 struct tty_struct *tty;
3367 unsigned long flags;
3369 pr_debug("stl_cd1400flowctrl(portp=%p,state=%x)\n", portp, state);
3377 spin_lock_irqsave(&brd_lock, flags);
3378 BRDENABLE(portp->brdnr, portp->pagenr);
3379 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3382 if (tty->termios->c_iflag & IXOFF) {
3383 stl_cd1400ccrwait(portp);
3384 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3385 portp->stats.rxxon++;
3386 stl_cd1400ccrwait(portp);
3389 * Question: should we return RTS to what it was before? It may
3390 * have been set by an ioctl... Suppose not, since if you have
3391 * hardware flow control set then it is pretty silly to go and
3392 * set the RTS line by hand.
3394 if (tty->termios->c_cflag & CRTSCTS) {
3395 stl_cd1400setreg(portp, MCOR1,
3396 (stl_cd1400getreg(portp, MCOR1) |
3397 FIFO_RTSTHRESHOLD));
3398 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3399 portp->stats.rxrtson++;
3402 if (tty->termios->c_iflag & IXOFF) {
3403 stl_cd1400ccrwait(portp);
3404 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3405 portp->stats.rxxoff++;
3406 stl_cd1400ccrwait(portp);
3408 if (tty->termios->c_cflag & CRTSCTS) {
3409 stl_cd1400setreg(portp, MCOR1,
3410 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3411 stl_cd1400setreg(portp, MSVR2, 0);
3412 portp->stats.rxrtsoff++;
3416 BRDDISABLE(portp->brdnr);
3417 spin_unlock_irqrestore(&brd_lock, flags);
3420 /*****************************************************************************/
3423 * Send a flow control character...
3426 static void stl_cd1400sendflow(struct stlport *portp, int state)
3428 struct tty_struct *tty;
3429 unsigned long flags;
3431 pr_debug("stl_cd1400sendflow(portp=%p,state=%x)\n", portp, state);
3439 spin_lock_irqsave(&brd_lock, flags);
3440 BRDENABLE(portp->brdnr, portp->pagenr);
3441 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3443 stl_cd1400ccrwait(portp);
3444 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3445 portp->stats.rxxon++;
3446 stl_cd1400ccrwait(portp);
3448 stl_cd1400ccrwait(portp);
3449 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3450 portp->stats.rxxoff++;
3451 stl_cd1400ccrwait(portp);
3453 BRDDISABLE(portp->brdnr);
3454 spin_unlock_irqrestore(&brd_lock, flags);
3457 /*****************************************************************************/
3459 static void stl_cd1400flush(struct stlport *portp)
3461 unsigned long flags;
3463 pr_debug("stl_cd1400flush(portp=%p)\n", portp);
3468 spin_lock_irqsave(&brd_lock, flags);
3469 BRDENABLE(portp->brdnr, portp->pagenr);
3470 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3471 stl_cd1400ccrwait(portp);
3472 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3473 stl_cd1400ccrwait(portp);
3474 portp->tx.tail = portp->tx.head;
3475 BRDDISABLE(portp->brdnr);
3476 spin_unlock_irqrestore(&brd_lock, flags);
3479 /*****************************************************************************/
3482 * Return the current state of data flow on this port. This is only
3483 * really interresting when determining if data has fully completed
3484 * transmission or not... This is easy for the cd1400, it accurately
3485 * maintains the busy port flag.
3488 static int stl_cd1400datastate(struct stlport *portp)
3490 pr_debug("stl_cd1400datastate(portp=%p)\n", portp);
3495 return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
3498 /*****************************************************************************/
3501 * Interrupt service routine for cd1400 EasyIO boards.
3504 static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase)
3506 unsigned char svrtype;
3508 pr_debug("stl_cd1400eiointr(panelp=%p,iobase=%x)\n", panelp, iobase);
3510 spin_lock(&brd_lock);
3512 svrtype = inb(iobase + EREG_DATA);
3513 if (panelp->nrports > 4) {
3514 outb((SVRR + 0x80), iobase);
3515 svrtype |= inb(iobase + EREG_DATA);
3518 if (svrtype & SVRR_RX)
3519 stl_cd1400rxisr(panelp, iobase);
3520 else if (svrtype & SVRR_TX)
3521 stl_cd1400txisr(panelp, iobase);
3522 else if (svrtype & SVRR_MDM)
3523 stl_cd1400mdmisr(panelp, iobase);
3525 spin_unlock(&brd_lock);
3528 /*****************************************************************************/
3531 * Interrupt service routine for cd1400 panels.
3534 static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase)
3536 unsigned char svrtype;
3538 pr_debug("stl_cd1400echintr(panelp=%p,iobase=%x)\n", panelp, iobase);
3541 svrtype = inb(iobase + EREG_DATA);
3542 outb((SVRR + 0x80), iobase);
3543 svrtype |= inb(iobase + EREG_DATA);
3544 if (svrtype & SVRR_RX)
3545 stl_cd1400rxisr(panelp, iobase);
3546 else if (svrtype & SVRR_TX)
3547 stl_cd1400txisr(panelp, iobase);
3548 else if (svrtype & SVRR_MDM)
3549 stl_cd1400mdmisr(panelp, iobase);
3553 /*****************************************************************************/
3556 * Unfortunately we need to handle breaks in the TX data stream, since
3557 * this is the only way to generate them on the cd1400.
3560 static int stl_cd1400breakisr(struct stlport *portp, int ioaddr)
3562 if (portp->brklen == 1) {
3563 outb((COR2 + portp->uartaddr), ioaddr);
3564 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
3565 (ioaddr + EREG_DATA));
3566 outb((TDR + portp->uartaddr), ioaddr);
3567 outb(ETC_CMD, (ioaddr + EREG_DATA));
3568 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
3569 outb((SRER + portp->uartaddr), ioaddr);
3570 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
3571 (ioaddr + EREG_DATA));
3573 } else if (portp->brklen > 1) {
3574 outb((TDR + portp->uartaddr), ioaddr);
3575 outb(ETC_CMD, (ioaddr + EREG_DATA));
3576 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
3580 outb((COR2 + portp->uartaddr), ioaddr);
3581 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
3582 (ioaddr + EREG_DATA));
3588 /*****************************************************************************/
3591 * Transmit interrupt handler. This has gotta be fast! Handling TX
3592 * chars is pretty simple, stuff as many as possible from the TX buffer
3593 * into the cd1400 FIFO. Must also handle TX breaks here, since they
3594 * are embedded as commands in the data stream. Oh no, had to use a goto!
3595 * This could be optimized more, will do when I get time...
3596 * In practice it is possible that interrupts are enabled but that the
3597 * port has been hung up. Need to handle not having any TX buffer here,
3598 * this is done by using the side effect that head and tail will also
3599 * be NULL if the buffer has been freed.
3602 static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr)
3604 struct stlport *portp;
3607 unsigned char ioack, srer;
3609 pr_debug("stl_cd1400txisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3611 ioack = inb(ioaddr + EREG_TXACK);
3612 if (((ioack & panelp->ackmask) != 0) ||
3613 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
3614 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
3617 portp = panelp->ports[(ioack >> 3)];
3620 * Unfortunately we need to handle breaks in the data stream, since
3621 * this is the only way to generate them on the cd1400. Do it now if
3622 * a break is to be sent.
3624 if (portp->brklen != 0)
3625 if (stl_cd1400breakisr(portp, ioaddr))
3628 head = portp->tx.head;
3629 tail = portp->tx.tail;
3630 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
3631 if ((len == 0) || ((len < STL_TXBUFLOW) &&
3632 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
3633 set_bit(ASYI_TXLOW, &portp->istate);
3634 schedule_work(&portp->tqueue);
3638 outb((SRER + portp->uartaddr), ioaddr);
3639 srer = inb(ioaddr + EREG_DATA);
3640 if (srer & SRER_TXDATA) {
3641 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
3643 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
3644 clear_bit(ASYI_TXBUSY, &portp->istate);
3646 outb(srer, (ioaddr + EREG_DATA));
3648 len = MIN(len, CD1400_TXFIFOSIZE);
3649 portp->stats.txtotal += len;
3650 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
3651 outb((TDR + portp->uartaddr), ioaddr);
3652 outsb((ioaddr + EREG_DATA), tail, stlen);
3655 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
3656 tail = portp->tx.buf;
3658 outsb((ioaddr + EREG_DATA), tail, len);
3661 portp->tx.tail = tail;
3665 outb((EOSRR + portp->uartaddr), ioaddr);
3666 outb(0, (ioaddr + EREG_DATA));
3669 /*****************************************************************************/
3672 * Receive character interrupt handler. Determine if we have good chars
3673 * or bad chars and then process appropriately. Good chars are easy
3674 * just shove the lot into the RX buffer and set all status byte to 0.
3675 * If a bad RX char then process as required. This routine needs to be
3676 * fast! In practice it is possible that we get an interrupt on a port
3677 * that is closed. This can happen on hangups - since they completely
3678 * shutdown a port not in user context. Need to handle this case.
3681 static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr)
3683 struct stlport *portp;
3684 struct tty_struct *tty;
3685 unsigned int ioack, len, buflen;
3686 unsigned char status;
3689 pr_debug("stl_cd1400rxisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3691 ioack = inb(ioaddr + EREG_RXACK);
3692 if ((ioack & panelp->ackmask) != 0) {
3693 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
3696 portp = panelp->ports[(ioack >> 3)];
3699 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
3700 outb((RDCR + portp->uartaddr), ioaddr);
3701 len = inb(ioaddr + EREG_DATA);
3702 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
3703 len = MIN(len, sizeof(stl_unwanted));
3704 outb((RDSR + portp->uartaddr), ioaddr);
3705 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
3706 portp->stats.rxlost += len;
3707 portp->stats.rxtotal += len;
3709 len = MIN(len, buflen);
3712 outb((RDSR + portp->uartaddr), ioaddr);
3713 tty_prepare_flip_string(tty, &ptr, len);
3714 insb((ioaddr + EREG_DATA), ptr, len);
3715 tty_schedule_flip(tty);
3716 portp->stats.rxtotal += len;
3719 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
3720 outb((RDSR + portp->uartaddr), ioaddr);
3721 status = inb(ioaddr + EREG_DATA);
3722 ch = inb(ioaddr + EREG_DATA);
3723 if (status & ST_PARITY)
3724 portp->stats.rxparity++;
3725 if (status & ST_FRAMING)
3726 portp->stats.rxframing++;
3727 if (status & ST_OVERRUN)
3728 portp->stats.rxoverrun++;
3729 if (status & ST_BREAK)
3730 portp->stats.rxbreaks++;
3731 if (status & ST_SCHARMASK) {
3732 if ((status & ST_SCHARMASK) == ST_SCHAR1)
3733 portp->stats.txxon++;
3734 if ((status & ST_SCHARMASK) == ST_SCHAR2)
3735 portp->stats.txxoff++;
3738 if (tty != NULL && (portp->rxignoremsk & status) == 0) {
3739 if (portp->rxmarkmsk & status) {
3740 if (status & ST_BREAK) {
3742 if (portp->flags & ASYNC_SAK) {
3744 BRDENABLE(portp->brdnr, portp->pagenr);
3746 } else if (status & ST_PARITY) {
3747 status = TTY_PARITY;
3748 } else if (status & ST_FRAMING) {
3750 } else if(status & ST_OVERRUN) {
3751 status = TTY_OVERRUN;
3758 tty_insert_flip_char(tty, ch, status);
3759 tty_schedule_flip(tty);
3762 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
3767 outb((EOSRR + portp->uartaddr), ioaddr);
3768 outb(0, (ioaddr + EREG_DATA));
3771 /*****************************************************************************/
3774 * Modem interrupt handler. The is called when the modem signal line
3775 * (DCD) has changed state. Leave most of the work to the off-level
3776 * processing routine.
3779 static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr)
3781 struct stlport *portp;
3785 pr_debug("stl_cd1400mdmisr(panelp=%p)\n", panelp);
3787 ioack = inb(ioaddr + EREG_MDACK);
3788 if (((ioack & panelp->ackmask) != 0) ||
3789 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
3790 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
3793 portp = panelp->ports[(ioack >> 3)];
3795 outb((MISR + portp->uartaddr), ioaddr);
3796 misr = inb(ioaddr + EREG_DATA);
3797 if (misr & MISR_DCD) {
3798 set_bit(ASYI_DCDCHANGE, &portp->istate);
3799 schedule_work(&portp->tqueue);
3800 portp->stats.modem++;
3803 outb((EOSRR + portp->uartaddr), ioaddr);
3804 outb(0, (ioaddr + EREG_DATA));
3807 /*****************************************************************************/
3808 /* SC26198 HARDWARE FUNCTIONS */
3809 /*****************************************************************************/
3812 * These functions get/set/update the registers of the sc26198 UARTs.
3813 * Access to the sc26198 registers is via an address/data io port pair.
3814 * (Maybe should make this inline...)
3817 static int stl_sc26198getreg(struct stlport *portp, int regnr)
3819 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3820 return inb(portp->ioaddr + XP_DATA);
3823 static void stl_sc26198setreg(struct stlport *portp, int regnr, int value)
3825 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3826 outb(value, (portp->ioaddr + XP_DATA));
3829 static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value)
3831 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3832 if (inb(portp->ioaddr + XP_DATA) != value) {
3833 outb(value, (portp->ioaddr + XP_DATA));
3839 /*****************************************************************************/
3842 * Functions to get and set the sc26198 global registers.
3845 static int stl_sc26198getglobreg(struct stlport *portp, int regnr)
3847 outb(regnr, (portp->ioaddr + XP_ADDR));
3848 return inb(portp->ioaddr + XP_DATA);
3852 static void stl_sc26198setglobreg(struct stlport *portp, int regnr, int value)
3854 outb(regnr, (portp->ioaddr + XP_ADDR));
3855 outb(value, (portp->ioaddr + XP_DATA));
3859 /*****************************************************************************/
3862 * Inbitialize the UARTs in a panel. We don't care what sort of board
3863 * these ports are on - since the port io registers are almost
3864 * identical when dealing with ports.
3867 static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
3870 int nrchips, ioaddr;
3872 pr_debug("stl_sc26198panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
3874 BRDENABLE(panelp->brdnr, panelp->pagenr);
3877 * Check that each chip is present and started up OK.
3880 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
3881 if (brdp->brdtype == BRD_ECHPCI)
3882 outb(panelp->pagenr, brdp->ioctrl);
3884 for (i = 0; (i < nrchips); i++) {
3885 ioaddr = panelp->iobase + (i * 4);
3886 outb(SCCR, (ioaddr + XP_ADDR));
3887 outb(CR_RESETALL, (ioaddr + XP_DATA));
3888 outb(TSTR, (ioaddr + XP_ADDR));
3889 if (inb(ioaddr + XP_DATA) != 0) {
3890 printk("STALLION: sc26198 not responding, "
3891 "brd=%d panel=%d chip=%d\n",
3892 panelp->brdnr, panelp->panelnr, i);
3895 chipmask |= (0x1 << i);
3896 outb(GCCR, (ioaddr + XP_ADDR));
3897 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
3898 outb(WDTRCR, (ioaddr + XP_ADDR));
3899 outb(0xff, (ioaddr + XP_DATA));
3902 BRDDISABLE(panelp->brdnr);
3906 /*****************************************************************************/
3909 * Initialize hardware specific port registers.
3912 static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
3914 pr_debug("stl_sc26198portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
3917 if ((brdp == NULL) || (panelp == NULL) ||
3921 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
3922 portp->uartaddr = (portp->portnr & 0x07) << 4;
3923 portp->pagenr = panelp->pagenr;
3926 BRDENABLE(portp->brdnr, portp->pagenr);
3927 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
3928 BRDDISABLE(portp->brdnr);
3931 /*****************************************************************************/
3934 * Set up the sc26198 registers for a port based on the termios port
3938 static void stl_sc26198setport(struct stlport *portp, struct ktermios *tiosp)
3940 struct stlbrd *brdp;
3941 unsigned long flags;
3942 unsigned int baudrate;
3943 unsigned char mr0, mr1, mr2, clk;
3944 unsigned char imron, imroff, iopr, ipr;
3954 brdp = stl_brds[portp->brdnr];
3959 * Set up the RX char ignore mask with those RX error types we
3962 portp->rxignoremsk = 0;
3963 if (tiosp->c_iflag & IGNPAR)
3964 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
3966 if (tiosp->c_iflag & IGNBRK)
3967 portp->rxignoremsk |= SR_RXBREAK;
3969 portp->rxmarkmsk = SR_RXOVERRUN;
3970 if (tiosp->c_iflag & (INPCK | PARMRK))
3971 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
3972 if (tiosp->c_iflag & BRKINT)
3973 portp->rxmarkmsk |= SR_RXBREAK;
3976 * Go through the char size, parity and stop bits and set all the
3977 * option register appropriately.
3979 switch (tiosp->c_cflag & CSIZE) {
3994 if (tiosp->c_cflag & CSTOPB)
3999 if (tiosp->c_cflag & PARENB) {
4000 if (tiosp->c_cflag & PARODD)
4001 mr1 |= (MR1_PARENB | MR1_PARODD);
4003 mr1 |= (MR1_PARENB | MR1_PAREVEN);
4008 mr1 |= MR1_ERRBLOCK;
4011 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4012 * space for hardware flow control and the like. This should be set to
4015 mr2 |= MR2_RXFIFOHALF;
4018 * Calculate the baud rate timers. For now we will just assume that
4019 * the input and output baud are the same. The sc26198 has a fixed
4020 * baud rate table, so only discrete baud rates possible.
4022 baudrate = tiosp->c_cflag & CBAUD;
4023 if (baudrate & CBAUDEX) {
4024 baudrate &= ~CBAUDEX;
4025 if ((baudrate < 1) || (baudrate > 4))
4026 tiosp->c_cflag &= ~CBAUDEX;
4030 baudrate = stl_baudrates[baudrate];
4031 if ((tiosp->c_cflag & CBAUD) == B38400) {
4032 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
4034 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
4036 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
4038 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
4040 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
4041 baudrate = (portp->baud_base / portp->custom_divisor);
4043 if (baudrate > STL_SC26198MAXBAUD)
4044 baudrate = STL_SC26198MAXBAUD;
4047 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
4048 if (baudrate <= sc26198_baudtable[clk])
4054 * Check what form of modem signaling is required and set it up.
4056 if (tiosp->c_cflag & CLOCAL) {
4057 portp->flags &= ~ASYNC_CHECK_CD;
4059 iopr |= IOPR_DCDCOS;
4061 portp->flags |= ASYNC_CHECK_CD;
4065 * Setup sc26198 enhanced modes if we can. In particular we want to
4066 * handle as much of the flow control as possible automatically. As
4067 * well as saving a few CPU cycles it will also greatly improve flow
4068 * control reliability.
4070 if (tiosp->c_iflag & IXON) {
4071 mr0 |= MR0_SWFTX | MR0_SWFT;
4072 imron |= IR_XONXOFF;
4074 imroff |= IR_XONXOFF;
4076 if (tiosp->c_iflag & IXOFF)
4079 if (tiosp->c_cflag & CRTSCTS) {
4085 * All sc26198 register values calculated so go through and set
4089 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4090 portp->portnr, portp->panelnr, portp->brdnr);
4091 pr_debug(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4092 pr_debug(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4093 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4094 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4095 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4097 spin_lock_irqsave(&brd_lock, flags);
4098 BRDENABLE(portp->brdnr, portp->pagenr);
4099 stl_sc26198setreg(portp, IMR, 0);
4100 stl_sc26198updatereg(portp, MR0, mr0);
4101 stl_sc26198updatereg(portp, MR1, mr1);
4102 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4103 stl_sc26198updatereg(portp, MR2, mr2);
4104 stl_sc26198updatereg(portp, IOPIOR,
4105 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
4108 stl_sc26198setreg(portp, TXCSR, clk);
4109 stl_sc26198setreg(portp, RXCSR, clk);
4112 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4113 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4115 ipr = stl_sc26198getreg(portp, IPR);
4117 portp->sigs &= ~TIOCM_CD;
4119 portp->sigs |= TIOCM_CD;
4121 portp->imr = (portp->imr & ~imroff) | imron;
4122 stl_sc26198setreg(portp, IMR, portp->imr);
4123 BRDDISABLE(portp->brdnr);
4124 spin_unlock_irqrestore(&brd_lock, flags);
4127 /*****************************************************************************/
4130 * Set the state of the DTR and RTS signals.
4133 static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts)
4135 unsigned char iopioron, iopioroff;
4136 unsigned long flags;
4138 pr_debug("stl_sc26198setsignals(portp=%p,dtr=%d,rts=%d)\n", portp,
4144 iopioroff |= IPR_DTR;
4146 iopioron |= IPR_DTR;
4148 iopioroff |= IPR_RTS;
4150 iopioron |= IPR_RTS;
4152 spin_lock_irqsave(&brd_lock, flags);
4153 BRDENABLE(portp->brdnr, portp->pagenr);
4154 stl_sc26198setreg(portp, IOPIOR,
4155 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4156 BRDDISABLE(portp->brdnr);
4157 spin_unlock_irqrestore(&brd_lock, flags);
4160 /*****************************************************************************/
4163 * Return the state of the signals.
4166 static int stl_sc26198getsignals(struct stlport *portp)
4169 unsigned long flags;
4172 pr_debug("stl_sc26198getsignals(portp=%p)\n", portp);
4174 spin_lock_irqsave(&brd_lock, flags);
4175 BRDENABLE(portp->brdnr, portp->pagenr);
4176 ipr = stl_sc26198getreg(portp, IPR);
4177 BRDDISABLE(portp->brdnr);
4178 spin_unlock_irqrestore(&brd_lock, flags);
4181 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4182 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4183 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4184 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4189 /*****************************************************************************/
4192 * Enable/Disable the Transmitter and/or Receiver.
4195 static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx)
4198 unsigned long flags;
4200 pr_debug("stl_sc26198enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx,tx);
4202 ccr = portp->crenable;
4204 ccr &= ~CR_TXENABLE;
4208 ccr &= ~CR_RXENABLE;
4212 spin_lock_irqsave(&brd_lock, flags);
4213 BRDENABLE(portp->brdnr, portp->pagenr);
4214 stl_sc26198setreg(portp, SCCR, ccr);
4215 BRDDISABLE(portp->brdnr);
4216 portp->crenable = ccr;
4217 spin_unlock_irqrestore(&brd_lock, flags);
4220 /*****************************************************************************/
4223 * Start/stop the Transmitter and/or Receiver.
4226 static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx)
4229 unsigned long flags;
4231 pr_debug("stl_sc26198startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
4239 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4241 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4243 spin_lock_irqsave(&brd_lock, flags);
4244 BRDENABLE(portp->brdnr, portp->pagenr);
4245 stl_sc26198setreg(portp, IMR, imr);
4246 BRDDISABLE(portp->brdnr);
4249 set_bit(ASYI_TXBUSY, &portp->istate);
4250 spin_unlock_irqrestore(&brd_lock, flags);
4253 /*****************************************************************************/
4256 * Disable all interrupts from this port.
4259 static void stl_sc26198disableintrs(struct stlport *portp)
4261 unsigned long flags;
4263 pr_debug("stl_sc26198disableintrs(portp=%p)\n", portp);
4265 spin_lock_irqsave(&brd_lock, flags);
4266 BRDENABLE(portp->brdnr, portp->pagenr);
4268 stl_sc26198setreg(portp, IMR, 0);
4269 BRDDISABLE(portp->brdnr);
4270 spin_unlock_irqrestore(&brd_lock, flags);
4273 /*****************************************************************************/
4275 static void stl_sc26198sendbreak(struct stlport *portp, int len)
4277 unsigned long flags;
4279 pr_debug("stl_sc26198sendbreak(portp=%p,len=%d)\n", portp, len);
4281 spin_lock_irqsave(&brd_lock, flags);
4282 BRDENABLE(portp->brdnr, portp->pagenr);
4284 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4285 portp->stats.txbreaks++;
4287 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4289 BRDDISABLE(portp->brdnr);
4290 spin_unlock_irqrestore(&brd_lock, flags);
4293 /*****************************************************************************/
4296 * Take flow control actions...
4299 static void stl_sc26198flowctrl(struct stlport *portp, int state)
4301 struct tty_struct *tty;
4302 unsigned long flags;
4305 pr_debug("stl_sc26198flowctrl(portp=%p,state=%x)\n", portp, state);
4313 spin_lock_irqsave(&brd_lock, flags);
4314 BRDENABLE(portp->brdnr, portp->pagenr);
4317 if (tty->termios->c_iflag & IXOFF) {
4318 mr0 = stl_sc26198getreg(portp, MR0);
4319 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4320 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4322 portp->stats.rxxon++;
4323 stl_sc26198wait(portp);
4324 stl_sc26198setreg(portp, MR0, mr0);
4327 * Question: should we return RTS to what it was before? It may
4328 * have been set by an ioctl... Suppose not, since if you have
4329 * hardware flow control set then it is pretty silly to go and
4330 * set the RTS line by hand.
4332 if (tty->termios->c_cflag & CRTSCTS) {
4333 stl_sc26198setreg(portp, MR1,
4334 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4335 stl_sc26198setreg(portp, IOPIOR,
4336 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4337 portp->stats.rxrtson++;
4340 if (tty->termios->c_iflag & IXOFF) {
4341 mr0 = stl_sc26198getreg(portp, MR0);
4342 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4343 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4345 portp->stats.rxxoff++;
4346 stl_sc26198wait(portp);
4347 stl_sc26198setreg(portp, MR0, mr0);
4349 if (tty->termios->c_cflag & CRTSCTS) {
4350 stl_sc26198setreg(portp, MR1,
4351 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4352 stl_sc26198setreg(portp, IOPIOR,
4353 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4354 portp->stats.rxrtsoff++;
4358 BRDDISABLE(portp->brdnr);
4359 spin_unlock_irqrestore(&brd_lock, flags);
4362 /*****************************************************************************/
4365 * Send a flow control character.
4368 static void stl_sc26198sendflow(struct stlport *portp, int state)
4370 struct tty_struct *tty;
4371 unsigned long flags;
4374 pr_debug("stl_sc26198sendflow(portp=%p,state=%x)\n", portp, state);
4382 spin_lock_irqsave(&brd_lock, flags);
4383 BRDENABLE(portp->brdnr, portp->pagenr);
4385 mr0 = stl_sc26198getreg(portp, MR0);
4386 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4387 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4389 portp->stats.rxxon++;
4390 stl_sc26198wait(portp);
4391 stl_sc26198setreg(portp, MR0, mr0);
4393 mr0 = stl_sc26198getreg(portp, MR0);
4394 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4395 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4397 portp->stats.rxxoff++;
4398 stl_sc26198wait(portp);
4399 stl_sc26198setreg(portp, MR0, mr0);
4401 BRDDISABLE(portp->brdnr);
4402 spin_unlock_irqrestore(&brd_lock, flags);
4405 /*****************************************************************************/
4407 static void stl_sc26198flush(struct stlport *portp)
4409 unsigned long flags;
4411 pr_debug("stl_sc26198flush(portp=%p)\n", portp);
4416 spin_lock_irqsave(&brd_lock, flags);
4417 BRDENABLE(portp->brdnr, portp->pagenr);
4418 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4419 stl_sc26198setreg(portp, SCCR, portp->crenable);
4420 BRDDISABLE(portp->brdnr);
4421 portp->tx.tail = portp->tx.head;
4422 spin_unlock_irqrestore(&brd_lock, flags);
4425 /*****************************************************************************/
4428 * Return the current state of data flow on this port. This is only
4429 * really interresting when determining if data has fully completed
4430 * transmission or not... The sc26198 interrupt scheme cannot
4431 * determine when all data has actually drained, so we need to
4432 * check the port statusy register to be sure.
4435 static int stl_sc26198datastate(struct stlport *portp)
4437 unsigned long flags;
4440 pr_debug("stl_sc26198datastate(portp=%p)\n", portp);
4444 if (test_bit(ASYI_TXBUSY, &portp->istate))
4447 spin_lock_irqsave(&brd_lock, flags);
4448 BRDENABLE(portp->brdnr, portp->pagenr);
4449 sr = stl_sc26198getreg(portp, SR);
4450 BRDDISABLE(portp->brdnr);
4451 spin_unlock_irqrestore(&brd_lock, flags);
4453 return (sr & SR_TXEMPTY) ? 0 : 1;
4456 /*****************************************************************************/
4459 * Delay for a small amount of time, to give the sc26198 a chance
4460 * to process a command...
4463 static void stl_sc26198wait(struct stlport *portp)
4467 pr_debug("stl_sc26198wait(portp=%p)\n", portp);
4472 for (i = 0; (i < 20); i++)
4473 stl_sc26198getglobreg(portp, TSTR);
4476 /*****************************************************************************/
4479 * If we are TX flow controlled and in IXANY mode then we may
4480 * need to unflow control here. We gotta do this because of the
4481 * automatic flow control modes of the sc26198.
4484 static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty)
4488 mr0 = stl_sc26198getreg(portp, MR0);
4489 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4490 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4491 stl_sc26198wait(portp);
4492 stl_sc26198setreg(portp, MR0, mr0);
4493 clear_bit(ASYI_TXFLOWED, &portp->istate);
4496 /*****************************************************************************/
4499 * Interrupt service routine for sc26198 panels.
4502 static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase)
4504 struct stlport *portp;
4507 spin_lock(&brd_lock);
4510 * Work around bug in sc26198 chip... Cannot have A6 address
4511 * line of UART high, else iack will be returned as 0.
4513 outb(0, (iobase + 1));
4515 iack = inb(iobase + XP_IACK);
4516 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4518 if (iack & IVR_RXDATA)
4519 stl_sc26198rxisr(portp, iack);
4520 else if (iack & IVR_TXDATA)
4521 stl_sc26198txisr(portp);
4523 stl_sc26198otherisr(portp, iack);
4525 spin_unlock(&brd_lock);
4528 /*****************************************************************************/
4531 * Transmit interrupt handler. This has gotta be fast! Handling TX
4532 * chars is pretty simple, stuff as many as possible from the TX buffer
4533 * into the sc26198 FIFO.
4534 * In practice it is possible that interrupts are enabled but that the
4535 * port has been hung up. Need to handle not having any TX buffer here,
4536 * this is done by using the side effect that head and tail will also
4537 * be NULL if the buffer has been freed.
4540 static void stl_sc26198txisr(struct stlport *portp)
4542 unsigned int ioaddr;
4547 pr_debug("stl_sc26198txisr(portp=%p)\n", portp);
4549 ioaddr = portp->ioaddr;
4550 head = portp->tx.head;
4551 tail = portp->tx.tail;
4552 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4553 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4554 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4555 set_bit(ASYI_TXLOW, &portp->istate);
4556 schedule_work(&portp->tqueue);
4560 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
4561 mr0 = inb(ioaddr + XP_DATA);
4562 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4563 portp->imr &= ~IR_TXRDY;
4564 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
4565 outb(portp->imr, (ioaddr + XP_DATA));
4566 clear_bit(ASYI_TXBUSY, &portp->istate);
4568 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4569 outb(mr0, (ioaddr + XP_DATA));
4572 len = MIN(len, SC26198_TXFIFOSIZE);
4573 portp->stats.txtotal += len;
4574 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4575 outb(GTXFIFO, (ioaddr + XP_ADDR));
4576 outsb((ioaddr + XP_DATA), tail, stlen);
4579 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4580 tail = portp->tx.buf;
4582 outsb((ioaddr + XP_DATA), tail, len);
4585 portp->tx.tail = tail;
4589 /*****************************************************************************/
4592 * Receive character interrupt handler. Determine if we have good chars
4593 * or bad chars and then process appropriately. Good chars are easy
4594 * just shove the lot into the RX buffer and set all status byte to 0.
4595 * If a bad RX char then process as required. This routine needs to be
4596 * fast! In practice it is possible that we get an interrupt on a port
4597 * that is closed. This can happen on hangups - since they completely
4598 * shutdown a port not in user context. Need to handle this case.
4601 static void stl_sc26198rxisr(struct stlport *portp, unsigned int iack)
4603 struct tty_struct *tty;
4604 unsigned int len, buflen, ioaddr;
4606 pr_debug("stl_sc26198rxisr(portp=%p,iack=%x)\n", portp, iack);
4609 ioaddr = portp->ioaddr;
4610 outb(GIBCR, (ioaddr + XP_ADDR));
4611 len = inb(ioaddr + XP_DATA) + 1;
4613 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
4614 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
4615 len = MIN(len, sizeof(stl_unwanted));
4616 outb(GRXFIFO, (ioaddr + XP_ADDR));
4617 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4618 portp->stats.rxlost += len;
4619 portp->stats.rxtotal += len;
4621 len = MIN(len, buflen);
4624 outb(GRXFIFO, (ioaddr + XP_ADDR));
4625 tty_prepare_flip_string(tty, &ptr, len);
4626 insb((ioaddr + XP_DATA), ptr, len);
4627 tty_schedule_flip(tty);
4628 portp->stats.rxtotal += len;
4632 stl_sc26198rxbadchars(portp);
4636 * If we are TX flow controlled and in IXANY mode then we may need
4637 * to unflow control here. We gotta do this because of the automatic
4638 * flow control modes of the sc26198.
4640 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
4641 if ((tty != NULL) &&
4642 (tty->termios != NULL) &&
4643 (tty->termios->c_iflag & IXANY)) {
4644 stl_sc26198txunflow(portp, tty);
4649 /*****************************************************************************/
4652 * Process an RX bad character.
4655 static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch)
4657 struct tty_struct *tty;
4658 unsigned int ioaddr;
4661 ioaddr = portp->ioaddr;
4663 if (status & SR_RXPARITY)
4664 portp->stats.rxparity++;
4665 if (status & SR_RXFRAMING)
4666 portp->stats.rxframing++;
4667 if (status & SR_RXOVERRUN)
4668 portp->stats.rxoverrun++;
4669 if (status & SR_RXBREAK)
4670 portp->stats.rxbreaks++;
4672 if ((tty != NULL) &&
4673 ((portp->rxignoremsk & status) == 0)) {
4674 if (portp->rxmarkmsk & status) {
4675 if (status & SR_RXBREAK) {
4677 if (portp->flags & ASYNC_SAK) {
4679 BRDENABLE(portp->brdnr, portp->pagenr);
4681 } else if (status & SR_RXPARITY) {
4682 status = TTY_PARITY;
4683 } else if (status & SR_RXFRAMING) {
4685 } else if(status & SR_RXOVERRUN) {
4686 status = TTY_OVERRUN;
4694 tty_insert_flip_char(tty, ch, status);
4695 tty_schedule_flip(tty);
4698 portp->stats.rxtotal++;
4702 /*****************************************************************************/
4705 * Process all characters in the RX FIFO of the UART. Check all char
4706 * status bytes as well, and process as required. We need to check
4707 * all bytes in the FIFO, in case some more enter the FIFO while we
4708 * are here. To get the exact character error type we need to switch
4709 * into CHAR error mode (that is why we need to make sure we empty
4713 static void stl_sc26198rxbadchars(struct stlport *portp)
4715 unsigned char status, mr1;
4719 * To get the precise error type for each character we must switch
4720 * back into CHAR error mode.
4722 mr1 = stl_sc26198getreg(portp, MR1);
4723 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
4725 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
4726 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
4727 ch = stl_sc26198getreg(portp, RXFIFO);
4728 stl_sc26198rxbadch(portp, status, ch);
4732 * To get correct interrupt class we must switch back into BLOCK
4735 stl_sc26198setreg(portp, MR1, mr1);
4738 /*****************************************************************************/
4741 * Other interrupt handler. This includes modem signals, flow
4742 * control actions, etc. Most stuff is left to off-level interrupt
4746 static void stl_sc26198otherisr(struct stlport *portp, unsigned int iack)
4748 unsigned char cir, ipr, xisr;
4750 pr_debug("stl_sc26198otherisr(portp=%p,iack=%x)\n", portp, iack);
4752 cir = stl_sc26198getglobreg(portp, CIR);
4754 switch (cir & CIR_SUBTYPEMASK) {
4756 ipr = stl_sc26198getreg(portp, IPR);
4757 if (ipr & IPR_DCDCHANGE) {
4758 set_bit(ASYI_DCDCHANGE, &portp->istate);
4759 schedule_work(&portp->tqueue);
4760 portp->stats.modem++;
4763 case CIR_SUBXONXOFF:
4764 xisr = stl_sc26198getreg(portp, XISR);
4765 if (xisr & XISR_RXXONGOT) {
4766 set_bit(ASYI_TXFLOWED, &portp->istate);
4767 portp->stats.txxoff++;
4769 if (xisr & XISR_RXXOFFGOT) {
4770 clear_bit(ASYI_TXFLOWED, &portp->istate);
4771 portp->stats.txxon++;
4775 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
4776 stl_sc26198rxbadchars(portp);
4784 * Loadable module initialization stuff.
4786 static int __init stallion_module_init(void)
4788 unsigned int i, retval;
4790 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
4792 spin_lock_init(&stallion_lock);
4793 spin_lock_init(&brd_lock);
4797 retval = pci_register_driver(&stl_pcidriver);
4801 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
4806 * Set up a character driver for per board stuff. This is mainly used
4807 * to do stats ioctls on the ports.
4809 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
4810 printk("STALLION: failed to register serial board device\n");
4812 stallion_class = class_create(THIS_MODULE, "staliomem");
4813 for (i = 0; i < 4; i++)
4814 class_device_create(stallion_class, NULL,
4815 MKDEV(STL_SIOMEMMAJOR, i), NULL,
4818 stl_serial->owner = THIS_MODULE;
4819 stl_serial->driver_name = stl_drvname;
4820 stl_serial->name = "ttyE";
4821 stl_serial->major = STL_SERIALMAJOR;
4822 stl_serial->minor_start = 0;
4823 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
4824 stl_serial->subtype = SERIAL_TYPE_NORMAL;
4825 stl_serial->init_termios = stl_deftermios;
4826 stl_serial->flags = TTY_DRIVER_REAL_RAW;
4827 tty_set_operations(stl_serial, &stl_ops);
4829 if (tty_register_driver(stl_serial)) {
4830 put_tty_driver(stl_serial);
4831 printk("STALLION: failed to register serial driver\n");
4840 static void __exit stallion_module_exit(void)
4842 struct stlbrd *brdp;
4845 pr_debug("cleanup_module()\n");
4847 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
4851 * Free up all allocated resources used by the ports. This includes
4852 * memory and interrupts. As part of this process we will also do
4853 * a hangup on every open port - to try to flush out any processes
4854 * hanging onto ports.
4856 i = tty_unregister_driver(stl_serial);
4857 put_tty_driver(stl_serial);
4859 printk("STALLION: failed to un-register tty driver, "
4863 for (i = 0; i < 4; i++)
4864 class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
4865 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
4866 printk("STALLION: failed to un-register serial memory device, "
4868 class_destroy(stallion_class);
4870 pci_unregister_driver(&stl_pcidriver);
4872 for (i = 0; (i < stl_nrbrds); i++) {
4873 if ((brdp = stl_brds[i]) == NULL)
4876 free_irq(brdp->irq, brdp);
4878 stl_cleanup_panels(brdp);
4880 release_region(brdp->ioaddr1, brdp->iosize1);
4881 if (brdp->iosize2 > 0)
4882 release_region(brdp->ioaddr2, brdp->iosize2);
4889 module_init(stallion_module_init);
4890 module_exit(stallion_module_exit);
4892 MODULE_AUTHOR("Greg Ungerer");
4893 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
4894 MODULE_LICENSE("GPL");