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>
44 #include <linux/ctype.h>
47 #include <asm/uaccess.h>
49 #include <linux/pci.h>
51 /*****************************************************************************/
54 * Define different board types. Use the standard Stallion "assigned"
55 * board numbers. Boards supported in this driver are abbreviated as
56 * EIO = EasyIO and ECH = EasyConnection 8/32.
62 #define BRD_ECH64PCI 27
63 #define BRD_EASYIOPCI 28
69 unsigned long memaddr;
74 static unsigned int stl_nrbrds;
76 /*****************************************************************************/
79 * Define some important driver characteristics. Device major numbers
80 * allocated as per Linux Device Registry.
82 #ifndef STL_SIOMEMMAJOR
83 #define STL_SIOMEMMAJOR 28
85 #ifndef STL_SERIALMAJOR
86 #define STL_SERIALMAJOR 24
88 #ifndef STL_CALLOUTMAJOR
89 #define STL_CALLOUTMAJOR 25
93 * Set the TX buffer size. Bigger is better, but we don't want
94 * to chew too much memory with buffers!
96 #define STL_TXBUFLOW 512
97 #define STL_TXBUFSIZE 4096
99 /*****************************************************************************/
102 * Define our local driver identity first. Set up stuff to deal with
103 * all the local structures required by a serial tty driver.
105 static char *stl_drvtitle = "Stallion Multiport Serial Driver";
106 static char *stl_drvname = "stallion";
107 static char *stl_drvversion = "5.6.0";
109 static struct tty_driver *stl_serial;
112 * Define a local default termios struct. All ports will be created
113 * with this termios initially. Basically all it defines is a raw port
114 * at 9600, 8 data bits, 1 stop bit.
116 static struct ktermios stl_deftermios = {
117 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
124 * Define global place to put buffer overflow characters.
126 static char stl_unwanted[SC26198_RXFIFOSIZE];
128 /*****************************************************************************/
130 static DEFINE_MUTEX(stl_brdslock);
131 static struct stlbrd *stl_brds[STL_MAXBRDS];
134 * Per board state flags. Used with the state field of the board struct.
135 * Not really much here!
137 #define BRD_FOUND 0x1
138 #define STL_PROBED 0x2
142 * Define the port structure istate flags. These set of flags are
143 * modified at interrupt time - so setting and reseting them needs
144 * to be atomic. Use the bit clear/setting routines for this.
146 #define ASYI_TXBUSY 1
148 #define ASYI_DCDCHANGE 3
149 #define ASYI_TXFLOWED 4
152 * Define an array of board names as printable strings. Handy for
153 * referencing boards when printing trace and stuff.
155 static char *stl_brdnames[] = {
187 /*****************************************************************************/
190 * Define some string labels for arguments passed from the module
191 * load line. These allow for easy board definitions, and easy
192 * modification of the io, memory and irq resoucres.
194 static unsigned int stl_nargs;
195 static char *board0[4];
196 static char *board1[4];
197 static char *board2[4];
198 static char *board3[4];
200 static char **stl_brdsp[] = {
208 * Define a set of common board names, and types. This is used to
209 * parse any module arguments.
216 { "easyio", BRD_EASYIO },
217 { "eio", BRD_EASYIO },
218 { "20", BRD_EASYIO },
219 { "ec8/32", BRD_ECH },
220 { "ec8/32-at", BRD_ECH },
221 { "ec8/32-isa", BRD_ECH },
223 { "echat", BRD_ECH },
225 { "ec8/32-mc", BRD_ECHMC },
226 { "ec8/32-mca", BRD_ECHMC },
227 { "echmc", BRD_ECHMC },
228 { "echmca", BRD_ECHMC },
230 { "ec8/32-pc", BRD_ECHPCI },
231 { "ec8/32-pci", BRD_ECHPCI },
232 { "26", BRD_ECHPCI },
233 { "ec8/64-pc", BRD_ECH64PCI },
234 { "ec8/64-pci", BRD_ECH64PCI },
235 { "ech-pci", BRD_ECH64PCI },
236 { "echpci", BRD_ECH64PCI },
237 { "echpc", BRD_ECH64PCI },
238 { "27", BRD_ECH64PCI },
239 { "easyio-pc", BRD_EASYIOPCI },
240 { "easyio-pci", BRD_EASYIOPCI },
241 { "eio-pci", BRD_EASYIOPCI },
242 { "eiopci", BRD_EASYIOPCI },
243 { "28", BRD_EASYIOPCI },
247 * Define the module agruments.
250 module_param_array(board0, charp, &stl_nargs, 0);
251 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
252 module_param_array(board1, charp, &stl_nargs, 0);
253 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
254 module_param_array(board2, charp, &stl_nargs, 0);
255 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
256 module_param_array(board3, charp, &stl_nargs, 0);
257 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
259 /*****************************************************************************/
262 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
263 * to the directly accessible io ports of these boards (not the uarts -
264 * they are in cd1400.h and sc26198.h).
266 #define EIO_8PORTRS 0x04
267 #define EIO_4PORTRS 0x05
268 #define EIO_8PORTDI 0x00
269 #define EIO_8PORTM 0x06
271 #define EIO_IDBITMASK 0x07
273 #define EIO_BRDMASK 0xf0
276 #define ID_BRD16 0x30
278 #define EIO_INTRPEND 0x08
279 #define EIO_INTEDGE 0x00
280 #define EIO_INTLEVEL 0x08
284 #define ECH_IDBITMASK 0xe0
285 #define ECH_BRDENABLE 0x08
286 #define ECH_BRDDISABLE 0x00
287 #define ECH_INTENABLE 0x01
288 #define ECH_INTDISABLE 0x00
289 #define ECH_INTLEVEL 0x02
290 #define ECH_INTEDGE 0x00
291 #define ECH_INTRPEND 0x01
292 #define ECH_BRDRESET 0x01
294 #define ECHMC_INTENABLE 0x01
295 #define ECHMC_BRDRESET 0x02
297 #define ECH_PNLSTATUS 2
298 #define ECH_PNL16PORT 0x20
299 #define ECH_PNLIDMASK 0x07
300 #define ECH_PNLXPID 0x40
301 #define ECH_PNLINTRPEND 0x80
303 #define ECH_ADDR2MASK 0x1e0
306 * Define the vector mapping bits for the programmable interrupt board
307 * hardware. These bits encode the interrupt for the board to use - it
308 * is software selectable (except the EIO-8M).
310 static unsigned char stl_vecmap[] = {
311 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
312 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
316 * Lock ordering is that you may not take stallion_lock holding
320 static spinlock_t brd_lock; /* Guard the board mapping */
321 static spinlock_t stallion_lock; /* Guard the tty driver */
324 * Set up enable and disable macros for the ECH boards. They require
325 * the secondary io address space to be activated and deactivated.
326 * This way all ECH boards can share their secondary io region.
327 * If this is an ECH-PCI board then also need to set the page pointer
328 * to point to the correct page.
330 #define BRDENABLE(brdnr,pagenr) \
331 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
332 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
333 stl_brds[(brdnr)]->ioctrl); \
334 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
335 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
337 #define BRDDISABLE(brdnr) \
338 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
339 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
340 stl_brds[(brdnr)]->ioctrl);
342 #define STL_CD1400MAXBAUD 230400
343 #define STL_SC26198MAXBAUD 460800
345 #define STL_BAUDBASE 115200
346 #define STL_CLOSEDELAY (5 * HZ / 10)
348 /*****************************************************************************/
351 * Define the Stallion PCI vendor and device IDs.
353 #ifndef PCI_VENDOR_ID_STALLION
354 #define PCI_VENDOR_ID_STALLION 0x124d
356 #ifndef PCI_DEVICE_ID_ECHPCI832
357 #define PCI_DEVICE_ID_ECHPCI832 0x0000
359 #ifndef PCI_DEVICE_ID_ECHPCI864
360 #define PCI_DEVICE_ID_ECHPCI864 0x0002
362 #ifndef PCI_DEVICE_ID_EIOPCI
363 #define PCI_DEVICE_ID_EIOPCI 0x0003
367 * Define structure to hold all Stallion PCI boards.
370 static struct pci_device_id stl_pcibrds[] = {
371 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864),
372 .driver_data = BRD_ECH64PCI },
373 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI),
374 .driver_data = BRD_EASYIOPCI },
375 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832),
376 .driver_data = BRD_ECHPCI },
377 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410),
378 .driver_data = BRD_ECHPCI },
381 MODULE_DEVICE_TABLE(pci, stl_pcibrds);
383 /*****************************************************************************/
386 * Define macros to extract a brd/port number from a minor number.
388 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
389 #define MINOR2PORT(min) ((min) & 0x3f)
392 * Define a baud rate table that converts termios baud rate selector
393 * into the actual baud rate value. All baud rate calculations are
394 * based on the actual baud rate required.
396 static unsigned int stl_baudrates[] = {
397 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
398 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
401 /*****************************************************************************/
404 * Declare all those functions in this driver!
407 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
408 static int stl_brdinit(struct stlbrd *brdp);
409 static int stl_getportstats(struct stlport *portp, comstats_t __user *cp);
410 static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp);
411 static int stl_waitcarrier(struct stlport *portp, struct file *filp);
414 * CD1400 uart specific handling functions.
416 static void stl_cd1400setreg(struct stlport *portp, int regnr, int value);
417 static int stl_cd1400getreg(struct stlport *portp, int regnr);
418 static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value);
419 static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
420 static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
421 static void stl_cd1400setport(struct stlport *portp, struct ktermios *tiosp);
422 static int stl_cd1400getsignals(struct stlport *portp);
423 static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts);
424 static void stl_cd1400ccrwait(struct stlport *portp);
425 static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx);
426 static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx);
427 static void stl_cd1400disableintrs(struct stlport *portp);
428 static void stl_cd1400sendbreak(struct stlport *portp, int len);
429 static void stl_cd1400flowctrl(struct stlport *portp, int state);
430 static void stl_cd1400sendflow(struct stlport *portp, int state);
431 static void stl_cd1400flush(struct stlport *portp);
432 static int stl_cd1400datastate(struct stlport *portp);
433 static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase);
434 static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase);
435 static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr);
436 static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr);
437 static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr);
439 static inline int stl_cd1400breakisr(struct stlport *portp, int ioaddr);
442 * SC26198 uart specific handling functions.
444 static void stl_sc26198setreg(struct stlport *portp, int regnr, int value);
445 static int stl_sc26198getreg(struct stlport *portp, int regnr);
446 static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value);
447 static int stl_sc26198getglobreg(struct stlport *portp, int regnr);
448 static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
449 static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
450 static void stl_sc26198setport(struct stlport *portp, struct ktermios *tiosp);
451 static int stl_sc26198getsignals(struct stlport *portp);
452 static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts);
453 static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx);
454 static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx);
455 static void stl_sc26198disableintrs(struct stlport *portp);
456 static void stl_sc26198sendbreak(struct stlport *portp, int len);
457 static void stl_sc26198flowctrl(struct stlport *portp, int state);
458 static void stl_sc26198sendflow(struct stlport *portp, int state);
459 static void stl_sc26198flush(struct stlport *portp);
460 static int stl_sc26198datastate(struct stlport *portp);
461 static void stl_sc26198wait(struct stlport *portp);
462 static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty);
463 static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase);
464 static void stl_sc26198txisr(struct stlport *port);
465 static void stl_sc26198rxisr(struct stlport *port, unsigned int iack);
466 static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch);
467 static void stl_sc26198rxbadchars(struct stlport *portp);
468 static void stl_sc26198otherisr(struct stlport *port, unsigned int iack);
470 /*****************************************************************************/
473 * Generic UART support structure.
475 typedef struct uart {
476 int (*panelinit)(struct stlbrd *brdp, struct stlpanel *panelp);
477 void (*portinit)(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
478 void (*setport)(struct stlport *portp, struct ktermios *tiosp);
479 int (*getsignals)(struct stlport *portp);
480 void (*setsignals)(struct stlport *portp, int dtr, int rts);
481 void (*enablerxtx)(struct stlport *portp, int rx, int tx);
482 void (*startrxtx)(struct stlport *portp, int rx, int tx);
483 void (*disableintrs)(struct stlport *portp);
484 void (*sendbreak)(struct stlport *portp, int len);
485 void (*flowctrl)(struct stlport *portp, int state);
486 void (*sendflow)(struct stlport *portp, int state);
487 void (*flush)(struct stlport *portp);
488 int (*datastate)(struct stlport *portp);
489 void (*intr)(struct stlpanel *panelp, unsigned int iobase);
493 * Define some macros to make calling these functions nice and clean.
495 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
496 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
497 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
498 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
499 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
500 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
501 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
502 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
503 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
504 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
505 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
506 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
507 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
509 /*****************************************************************************/
512 * CD1400 UART specific data initialization.
514 static uart_t stl_cd1400uart = {
518 stl_cd1400getsignals,
519 stl_cd1400setsignals,
520 stl_cd1400enablerxtx,
522 stl_cd1400disableintrs,
532 * Define the offsets within the register bank of a cd1400 based panel.
533 * These io address offsets are common to the EasyIO board as well.
541 #define EREG_BANKSIZE 8
543 #define CD1400_CLK 25000000
544 #define CD1400_CLK8M 20000000
547 * Define the cd1400 baud rate clocks. These are used when calculating
548 * what clock and divisor to use for the required baud rate. Also
549 * define the maximum baud rate allowed, and the default base baud.
551 static int stl_cd1400clkdivs[] = {
552 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
555 /*****************************************************************************/
558 * SC26198 UART specific data initization.
560 static uart_t stl_sc26198uart = {
561 stl_sc26198panelinit,
564 stl_sc26198getsignals,
565 stl_sc26198setsignals,
566 stl_sc26198enablerxtx,
567 stl_sc26198startrxtx,
568 stl_sc26198disableintrs,
569 stl_sc26198sendbreak,
573 stl_sc26198datastate,
578 * Define the offsets within the register bank of a sc26198 based panel.
586 #define XP_BANKSIZE 4
589 * Define the sc26198 baud rate table. Offsets within the table
590 * represent the actual baud rate selector of sc26198 registers.
592 static unsigned int sc26198_baudtable[] = {
593 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
594 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
595 230400, 460800, 921600
598 #define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
600 /*****************************************************************************/
603 * Define the driver info for a user level control device. Used mainly
604 * to get at port stats - only not using the port device itself.
606 static const struct file_operations stl_fsiomem = {
607 .owner = THIS_MODULE,
608 .ioctl = stl_memioctl,
611 static struct class *stallion_class;
614 * Check for any arguments passed in on the module load command line.
617 /*****************************************************************************/
620 * Parse the supplied argument string, into the board conf struct.
623 static int __init stl_parsebrd(struct stlconf *confp, char **argp)
628 pr_debug("stl_parsebrd(confp=%p,argp=%p)\n", confp, argp);
630 if ((argp[0] == NULL) || (*argp[0] == 0))
633 for (sp = argp[0], i = 0; (*sp != 0) && (i < 25); sp++, i++)
636 for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++)
637 if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
640 if (i == ARRAY_SIZE(stl_brdstr)) {
641 printk("STALLION: unknown board name, %s?\n", argp[0]);
645 confp->brdtype = stl_brdstr[i].type;
648 if ((argp[i] != NULL) && (*argp[i] != 0))
649 confp->ioaddr1 = simple_strtoul(argp[i], NULL, 0);
651 if (confp->brdtype == BRD_ECH) {
652 if ((argp[i] != NULL) && (*argp[i] != 0))
653 confp->ioaddr2 = simple_strtoul(argp[i], NULL, 0);
656 if ((argp[i] != NULL) && (*argp[i] != 0))
657 confp->irq = simple_strtoul(argp[i], NULL, 0);
661 /*****************************************************************************/
664 * Allocate a new board structure. Fill out the basic info in it.
667 static struct stlbrd *stl_allocbrd(void)
671 brdp = kzalloc(sizeof(struct stlbrd), GFP_KERNEL);
673 printk("STALLION: failed to allocate memory (size=%Zd)\n",
674 sizeof(struct stlbrd));
678 brdp->magic = STL_BOARDMAGIC;
682 /*****************************************************************************/
684 static int stl_open(struct tty_struct *tty, struct file *filp)
686 struct stlport *portp;
688 unsigned int minordev, brdnr, panelnr;
691 pr_debug("stl_open(tty=%p,filp=%p): device=%s\n", tty, filp, tty->name);
693 minordev = tty->index;
694 brdnr = MINOR2BRD(minordev);
695 if (brdnr >= stl_nrbrds)
697 brdp = stl_brds[brdnr];
700 minordev = MINOR2PORT(minordev);
701 for (portnr = -1, panelnr = 0; panelnr < STL_MAXPANELS; panelnr++) {
702 if (brdp->panels[panelnr] == NULL)
704 if (minordev < brdp->panels[panelnr]->nrports) {
708 minordev -= brdp->panels[panelnr]->nrports;
713 portp = brdp->panels[panelnr]->ports[portnr];
718 * On the first open of the device setup the port hardware, and
719 * initialize the per port data structure.
722 tty->driver_data = portp;
725 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
726 if (!portp->tx.buf) {
727 portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
730 portp->tx.head = portp->tx.buf;
731 portp->tx.tail = portp->tx.buf;
733 stl_setport(portp, tty->termios);
734 portp->sigs = stl_getsignals(portp);
735 stl_setsignals(portp, 1, 1);
736 stl_enablerxtx(portp, 1, 1);
737 stl_startrxtx(portp, 1, 0);
738 clear_bit(TTY_IO_ERROR, &tty->flags);
739 portp->flags |= ASYNC_INITIALIZED;
743 * Check if this port is in the middle of closing. If so then wait
744 * until it is closed then return error status, based on flag settings.
745 * The sleep here does not need interrupt protection since the wakeup
746 * for it is done with the same context.
748 if (portp->flags & ASYNC_CLOSING) {
749 interruptible_sleep_on(&portp->close_wait);
750 if (portp->flags & ASYNC_HUP_NOTIFY)
756 * Based on type of open being done check if it can overlap with any
757 * previous opens still in effect. If we are a normal serial device
758 * then also we might have to wait for carrier.
760 if (!(filp->f_flags & O_NONBLOCK))
761 if ((rc = stl_waitcarrier(portp, filp)) != 0)
764 portp->flags |= ASYNC_NORMAL_ACTIVE;
769 /*****************************************************************************/
772 * Possibly need to wait for carrier (DCD signal) to come high. Say
773 * maybe because if we are clocal then we don't need to wait...
776 static int stl_waitcarrier(struct stlport *portp, struct file *filp)
781 pr_debug("stl_waitcarrier(portp=%p,filp=%p)\n", portp, filp);
786 spin_lock_irqsave(&stallion_lock, flags);
788 if (portp->tty->termios->c_cflag & CLOCAL)
791 portp->openwaitcnt++;
792 if (! tty_hung_up_p(filp))
796 /* Takes brd_lock internally */
797 stl_setsignals(portp, 1, 1);
798 if (tty_hung_up_p(filp) ||
799 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
800 if (portp->flags & ASYNC_HUP_NOTIFY)
806 if (((portp->flags & ASYNC_CLOSING) == 0) &&
807 (doclocal || (portp->sigs & TIOCM_CD)))
809 if (signal_pending(current)) {
814 interruptible_sleep_on(&portp->open_wait);
817 if (! tty_hung_up_p(filp))
819 portp->openwaitcnt--;
820 spin_unlock_irqrestore(&stallion_lock, flags);
825 /*****************************************************************************/
827 static void stl_flushbuffer(struct tty_struct *tty)
829 struct stlport *portp;
831 pr_debug("stl_flushbuffer(tty=%p)\n", tty);
835 portp = tty->driver_data;
843 /*****************************************************************************/
845 static void stl_waituntilsent(struct tty_struct *tty, int timeout)
847 struct stlport *portp;
850 pr_debug("stl_waituntilsent(tty=%p,timeout=%d)\n", tty, timeout);
854 portp = tty->driver_data;
860 tend = jiffies + timeout;
862 while (stl_datastate(portp)) {
863 if (signal_pending(current))
865 msleep_interruptible(20);
866 if (time_after_eq(jiffies, tend))
871 /*****************************************************************************/
873 static void stl_close(struct tty_struct *tty, struct file *filp)
875 struct stlport *portp;
878 pr_debug("stl_close(tty=%p,filp=%p)\n", tty, filp);
880 portp = tty->driver_data;
884 spin_lock_irqsave(&stallion_lock, flags);
885 if (tty_hung_up_p(filp)) {
886 spin_unlock_irqrestore(&stallion_lock, flags);
889 if ((tty->count == 1) && (portp->refcount != 1))
891 if (portp->refcount-- > 1) {
892 spin_unlock_irqrestore(&stallion_lock, flags);
897 portp->flags |= ASYNC_CLOSING;
900 * May want to wait for any data to drain before closing. The BUSY
901 * flag keeps track of whether we are still sending or not - it is
902 * very accurate for the cd1400, not quite so for the sc26198.
903 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
907 spin_unlock_irqrestore(&stallion_lock, flags);
909 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
910 tty_wait_until_sent(tty, portp->closing_wait);
911 stl_waituntilsent(tty, (HZ / 2));
914 spin_lock_irqsave(&stallion_lock, flags);
915 portp->flags &= ~ASYNC_INITIALIZED;
916 spin_unlock_irqrestore(&stallion_lock, flags);
918 stl_disableintrs(portp);
919 if (tty->termios->c_cflag & HUPCL)
920 stl_setsignals(portp, 0, 0);
921 stl_enablerxtx(portp, 0, 0);
922 stl_flushbuffer(tty);
924 if (portp->tx.buf != NULL) {
925 kfree(portp->tx.buf);
926 portp->tx.buf = NULL;
927 portp->tx.head = NULL;
928 portp->tx.tail = NULL;
930 set_bit(TTY_IO_ERROR, &tty->flags);
931 tty_ldisc_flush(tty);
936 if (portp->openwaitcnt) {
937 if (portp->close_delay)
938 msleep_interruptible(jiffies_to_msecs(portp->close_delay));
939 wake_up_interruptible(&portp->open_wait);
942 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
943 wake_up_interruptible(&portp->close_wait);
946 /*****************************************************************************/
949 * Write routine. Take data and stuff it in to the TX ring queue.
950 * If transmit interrupts are not running then start them.
953 static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
955 struct stlport *portp;
956 unsigned int len, stlen;
957 unsigned char *chbuf;
960 pr_debug("stl_write(tty=%p,buf=%p,count=%d)\n", tty, buf, count);
962 portp = tty->driver_data;
965 if (portp->tx.buf == NULL)
969 * If copying direct from user space we must cater for page faults,
970 * causing us to "sleep" here for a while. To handle this copy in all
971 * the data we need now, into a local buffer. Then when we got it all
972 * copy it into the TX buffer.
974 chbuf = (unsigned char *) buf;
976 head = portp->tx.head;
977 tail = portp->tx.tail;
979 len = STL_TXBUFSIZE - (head - tail) - 1;
980 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
982 len = tail - head - 1;
986 len = min(len, (unsigned int)count);
989 stlen = min(len, stlen);
990 memcpy(head, chbuf, stlen);
995 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
996 head = portp->tx.buf;
1000 portp->tx.head = head;
1002 clear_bit(ASYI_TXLOW, &portp->istate);
1003 stl_startrxtx(portp, -1, 1);
1008 /*****************************************************************************/
1010 static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1012 struct stlport *portp;
1016 pr_debug("stl_putchar(tty=%p,ch=%x)\n", tty, ch);
1020 portp = tty->driver_data;
1023 if (portp->tx.buf == NULL)
1026 head = portp->tx.head;
1027 tail = portp->tx.tail;
1029 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
1034 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
1035 head = portp->tx.buf;
1037 portp->tx.head = head;
1040 /*****************************************************************************/
1043 * If there are any characters in the buffer then make sure that TX
1044 * interrupts are on and get'em out. Normally used after the putchar
1045 * routine has been called.
1048 static void stl_flushchars(struct tty_struct *tty)
1050 struct stlport *portp;
1052 pr_debug("stl_flushchars(tty=%p)\n", tty);
1056 portp = tty->driver_data;
1059 if (portp->tx.buf == NULL)
1062 stl_startrxtx(portp, -1, 1);
1065 /*****************************************************************************/
1067 static int stl_writeroom(struct tty_struct *tty)
1069 struct stlport *portp;
1072 pr_debug("stl_writeroom(tty=%p)\n", tty);
1076 portp = tty->driver_data;
1079 if (portp->tx.buf == NULL)
1082 head = portp->tx.head;
1083 tail = portp->tx.tail;
1084 return (head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1);
1087 /*****************************************************************************/
1090 * Return number of chars in the TX buffer. Normally we would just
1091 * calculate the number of chars in the buffer and return that, but if
1092 * the buffer is empty and TX interrupts are still on then we return
1093 * that the buffer still has 1 char in it. This way whoever called us
1094 * will not think that ALL chars have drained - since the UART still
1095 * must have some chars in it (we are busy after all).
1098 static int stl_charsinbuffer(struct tty_struct *tty)
1100 struct stlport *portp;
1104 pr_debug("stl_charsinbuffer(tty=%p)\n", tty);
1108 portp = tty->driver_data;
1111 if (portp->tx.buf == NULL)
1114 head = portp->tx.head;
1115 tail = portp->tx.tail;
1116 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1117 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1122 /*****************************************************************************/
1125 * Generate the serial struct info.
1128 static int stl_getserial(struct stlport *portp, struct serial_struct __user *sp)
1130 struct serial_struct sio;
1131 struct stlbrd *brdp;
1133 pr_debug("stl_getserial(portp=%p,sp=%p)\n", portp, sp);
1135 memset(&sio, 0, sizeof(struct serial_struct));
1136 sio.line = portp->portnr;
1137 sio.port = portp->ioaddr;
1138 sio.flags = portp->flags;
1139 sio.baud_base = portp->baud_base;
1140 sio.close_delay = portp->close_delay;
1141 sio.closing_wait = portp->closing_wait;
1142 sio.custom_divisor = portp->custom_divisor;
1144 if (portp->uartp == &stl_cd1400uart) {
1145 sio.type = PORT_CIRRUS;
1146 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1148 sio.type = PORT_UNKNOWN;
1149 sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1152 brdp = stl_brds[portp->brdnr];
1154 sio.irq = brdp->irq;
1156 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
1159 /*****************************************************************************/
1162 * Set port according to the serial struct info.
1163 * At this point we do not do any auto-configure stuff, so we will
1164 * just quietly ignore any requests to change irq, etc.
1167 static int stl_setserial(struct stlport *portp, struct serial_struct __user *sp)
1169 struct serial_struct sio;
1171 pr_debug("stl_setserial(portp=%p,sp=%p)\n", portp, sp);
1173 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1175 if (!capable(CAP_SYS_ADMIN)) {
1176 if ((sio.baud_base != portp->baud_base) ||
1177 (sio.close_delay != portp->close_delay) ||
1178 ((sio.flags & ~ASYNC_USR_MASK) !=
1179 (portp->flags & ~ASYNC_USR_MASK)))
1183 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1184 (sio.flags & ASYNC_USR_MASK);
1185 portp->baud_base = sio.baud_base;
1186 portp->close_delay = sio.close_delay;
1187 portp->closing_wait = sio.closing_wait;
1188 portp->custom_divisor = sio.custom_divisor;
1189 stl_setport(portp, portp->tty->termios);
1193 /*****************************************************************************/
1195 static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1197 struct stlport *portp;
1201 portp = tty->driver_data;
1204 if (tty->flags & (1 << TTY_IO_ERROR))
1207 return stl_getsignals(portp);
1210 static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1211 unsigned int set, unsigned int clear)
1213 struct stlport *portp;
1214 int rts = -1, dtr = -1;
1218 portp = tty->driver_data;
1221 if (tty->flags & (1 << TTY_IO_ERROR))
1224 if (set & TIOCM_RTS)
1226 if (set & TIOCM_DTR)
1228 if (clear & TIOCM_RTS)
1230 if (clear & TIOCM_DTR)
1233 stl_setsignals(portp, dtr, rts);
1237 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1239 struct stlport *portp;
1242 void __user *argp = (void __user *)arg;
1244 pr_debug("stl_ioctl(tty=%p,file=%p,cmd=%x,arg=%lx)\n", tty, file, cmd,
1249 portp = tty->driver_data;
1253 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1254 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS))
1255 if (tty->flags & (1 << TTY_IO_ERROR))
1262 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1263 (unsigned __user *) argp);
1266 if (get_user(ival, (unsigned int __user *) arg))
1268 tty->termios->c_cflag =
1269 (tty->termios->c_cflag & ~CLOCAL) |
1270 (ival ? CLOCAL : 0);
1273 rc = stl_getserial(portp, argp);
1276 rc = stl_setserial(portp, argp);
1278 case COM_GETPORTSTATS:
1279 rc = stl_getportstats(portp, argp);
1281 case COM_CLRPORTSTATS:
1282 rc = stl_clrportstats(portp, argp);
1288 case TIOCSERGSTRUCT:
1289 case TIOCSERGETMULTI:
1290 case TIOCSERSETMULTI:
1299 /*****************************************************************************/
1302 * Start the transmitter again. Just turn TX interrupts back on.
1305 static void stl_start(struct tty_struct *tty)
1307 struct stlport *portp;
1309 pr_debug("stl_start(tty=%p)\n", tty);
1313 portp = tty->driver_data;
1316 stl_startrxtx(portp, -1, 1);
1319 /*****************************************************************************/
1321 static void stl_settermios(struct tty_struct *tty, struct ktermios *old)
1323 struct stlport *portp;
1324 struct ktermios *tiosp;
1326 pr_debug("stl_settermios(tty=%p,old=%p)\n", tty, old);
1330 portp = tty->driver_data;
1334 tiosp = tty->termios;
1335 if ((tiosp->c_cflag == old->c_cflag) &&
1336 (tiosp->c_iflag == old->c_iflag))
1339 stl_setport(portp, tiosp);
1340 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1342 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1343 tty->hw_stopped = 0;
1346 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1347 wake_up_interruptible(&portp->open_wait);
1350 /*****************************************************************************/
1353 * Attempt to flow control who ever is sending us data. Based on termios
1354 * settings use software or/and hardware flow control.
1357 static void stl_throttle(struct tty_struct *tty)
1359 struct stlport *portp;
1361 pr_debug("stl_throttle(tty=%p)\n", tty);
1365 portp = tty->driver_data;
1368 stl_flowctrl(portp, 0);
1371 /*****************************************************************************/
1374 * Unflow control the device sending us data...
1377 static void stl_unthrottle(struct tty_struct *tty)
1379 struct stlport *portp;
1381 pr_debug("stl_unthrottle(tty=%p)\n", tty);
1385 portp = tty->driver_data;
1388 stl_flowctrl(portp, 1);
1391 /*****************************************************************************/
1394 * Stop the transmitter. Basically to do this we will just turn TX
1398 static void stl_stop(struct tty_struct *tty)
1400 struct stlport *portp;
1402 pr_debug("stl_stop(tty=%p)\n", tty);
1406 portp = tty->driver_data;
1409 stl_startrxtx(portp, -1, 0);
1412 /*****************************************************************************/
1415 * Hangup this port. This is pretty much like closing the port, only
1416 * a little more brutal. No waiting for data to drain. Shutdown the
1417 * port and maybe drop signals.
1420 static void stl_hangup(struct tty_struct *tty)
1422 struct stlport *portp;
1424 pr_debug("stl_hangup(tty=%p)\n", tty);
1428 portp = tty->driver_data;
1432 portp->flags &= ~ASYNC_INITIALIZED;
1433 stl_disableintrs(portp);
1434 if (tty->termios->c_cflag & HUPCL)
1435 stl_setsignals(portp, 0, 0);
1436 stl_enablerxtx(portp, 0, 0);
1437 stl_flushbuffer(tty);
1439 set_bit(TTY_IO_ERROR, &tty->flags);
1440 if (portp->tx.buf != NULL) {
1441 kfree(portp->tx.buf);
1442 portp->tx.buf = NULL;
1443 portp->tx.head = NULL;
1444 portp->tx.tail = NULL;
1447 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1448 portp->refcount = 0;
1449 wake_up_interruptible(&portp->open_wait);
1452 /*****************************************************************************/
1454 static void stl_breakctl(struct tty_struct *tty, int state)
1456 struct stlport *portp;
1458 pr_debug("stl_breakctl(tty=%p,state=%d)\n", tty, state);
1462 portp = tty->driver_data;
1466 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1469 /*****************************************************************************/
1471 static void stl_sendxchar(struct tty_struct *tty, char ch)
1473 struct stlport *portp;
1475 pr_debug("stl_sendxchar(tty=%p,ch=%x)\n", tty, ch);
1479 portp = tty->driver_data;
1483 if (ch == STOP_CHAR(tty))
1484 stl_sendflow(portp, 0);
1485 else if (ch == START_CHAR(tty))
1486 stl_sendflow(portp, 1);
1488 stl_putchar(tty, ch);
1491 /*****************************************************************************/
1496 * Format info for a specified port. The line is deliberately limited
1497 * to 80 characters. (If it is too long it will be truncated, if too
1498 * short then padded with spaces).
1501 static int stl_portinfo(struct stlport *portp, int portnr, char *pos)
1507 sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
1508 portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
1509 (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
1511 if (portp->stats.rxframing)
1512 sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
1513 if (portp->stats.rxparity)
1514 sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
1515 if (portp->stats.rxbreaks)
1516 sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
1517 if (portp->stats.rxoverrun)
1518 sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
1520 sigs = stl_getsignals(portp);
1521 cnt = sprintf(sp, "%s%s%s%s%s ",
1522 (sigs & TIOCM_RTS) ? "|RTS" : "",
1523 (sigs & TIOCM_CTS) ? "|CTS" : "",
1524 (sigs & TIOCM_DTR) ? "|DTR" : "",
1525 (sigs & TIOCM_CD) ? "|DCD" : "",
1526 (sigs & TIOCM_DSR) ? "|DSR" : "");
1530 for (cnt = sp - pos; cnt < (MAXLINE - 1); cnt++)
1533 pos[(MAXLINE - 2)] = '+';
1534 pos[(MAXLINE - 1)] = '\n';
1539 /*****************************************************************************/
1542 * Port info, read from the /proc file system.
1545 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
1547 struct stlbrd *brdp;
1548 struct stlpanel *panelp;
1549 struct stlport *portp;
1550 unsigned int brdnr, panelnr, portnr;
1551 int totalport, curoff, maxoff;
1554 pr_debug("stl_readproc(page=%p,start=%p,off=%lx,count=%d,eof=%p,"
1555 "data=%p\n", page, start, off, count, eof, data);
1562 pos += sprintf(pos, "%s: version %s", stl_drvtitle,
1564 while (pos < (page + MAXLINE - 1))
1571 * We scan through for each board, panel and port. The offset is
1572 * calculated on the fly, and irrelevant ports are skipped.
1574 for (brdnr = 0; brdnr < stl_nrbrds; brdnr++) {
1575 brdp = stl_brds[brdnr];
1578 if (brdp->state == 0)
1581 maxoff = curoff + (brdp->nrports * MAXLINE);
1582 if (off >= maxoff) {
1587 totalport = brdnr * STL_MAXPORTS;
1588 for (panelnr = 0; panelnr < brdp->nrpanels; panelnr++) {
1589 panelp = brdp->panels[panelnr];
1593 maxoff = curoff + (panelp->nrports * MAXLINE);
1594 if (off >= maxoff) {
1596 totalport += panelp->nrports;
1600 for (portnr = 0; portnr < panelp->nrports; portnr++,
1602 portp = panelp->ports[portnr];
1605 if (off >= (curoff += MAXLINE))
1607 if ((pos - page + MAXLINE) > count)
1609 pos += stl_portinfo(portp, totalport, pos);
1621 /*****************************************************************************/
1624 * All board interrupts are vectored through here first. This code then
1625 * calls off to the approrpriate board interrupt handlers.
1628 static irqreturn_t stl_intr(int irq, void *dev_id)
1630 struct stlbrd *brdp = dev_id;
1632 pr_debug("stl_intr(brdp=%p,irq=%d)\n", brdp, irq);
1634 return IRQ_RETVAL((* brdp->isr)(brdp));
1637 /*****************************************************************************/
1640 * Interrupt service routine for EasyIO board types.
1643 static int stl_eiointr(struct stlbrd *brdp)
1645 struct stlpanel *panelp;
1646 unsigned int iobase;
1649 spin_lock(&brd_lock);
1650 panelp = brdp->panels[0];
1651 iobase = panelp->iobase;
1652 while (inb(brdp->iostatus) & EIO_INTRPEND) {
1654 (* panelp->isr)(panelp, iobase);
1656 spin_unlock(&brd_lock);
1660 /*****************************************************************************/
1663 * Interrupt service routine for ECH-AT board types.
1666 static int stl_echatintr(struct stlbrd *brdp)
1668 struct stlpanel *panelp;
1669 unsigned int ioaddr, bnknr;
1672 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
1674 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1676 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
1677 ioaddr = brdp->bnkstataddr[bnknr];
1678 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1679 panelp = brdp->bnk2panel[bnknr];
1680 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1685 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
1690 /*****************************************************************************/
1693 * Interrupt service routine for ECH-MCA board types.
1696 static int stl_echmcaintr(struct stlbrd *brdp)
1698 struct stlpanel *panelp;
1699 unsigned int ioaddr, bnknr;
1702 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1704 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
1705 ioaddr = brdp->bnkstataddr[bnknr];
1706 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1707 panelp = brdp->bnk2panel[bnknr];
1708 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1715 /*****************************************************************************/
1718 * Interrupt service routine for ECH-PCI board types.
1721 static int stl_echpciintr(struct stlbrd *brdp)
1723 struct stlpanel *panelp;
1724 unsigned int ioaddr, bnknr, recheck;
1729 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
1730 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
1731 ioaddr = brdp->bnkstataddr[bnknr];
1732 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1733 panelp = brdp->bnk2panel[bnknr];
1734 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1745 /*****************************************************************************/
1748 * Interrupt service routine for ECH-8/64-PCI board types.
1751 static int stl_echpci64intr(struct stlbrd *brdp)
1753 struct stlpanel *panelp;
1754 unsigned int ioaddr, bnknr;
1757 while (inb(brdp->ioctrl) & 0x1) {
1759 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
1760 ioaddr = brdp->bnkstataddr[bnknr];
1761 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1762 panelp = brdp->bnk2panel[bnknr];
1763 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1771 /*****************************************************************************/
1774 * Service an off-level request for some channel.
1776 static void stl_offintr(struct work_struct *work)
1778 struct stlport *portp = container_of(work, struct stlport, tqueue);
1779 struct tty_struct *tty;
1780 unsigned int oldsigs;
1782 pr_debug("stl_offintr(portp=%p)\n", portp);
1792 if (test_bit(ASYI_TXLOW, &portp->istate))
1795 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
1796 clear_bit(ASYI_DCDCHANGE, &portp->istate);
1797 oldsigs = portp->sigs;
1798 portp->sigs = stl_getsignals(portp);
1799 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
1800 wake_up_interruptible(&portp->open_wait);
1801 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0))
1802 if (portp->flags & ASYNC_CHECK_CD)
1803 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
1808 /*****************************************************************************/
1811 * Initialize all the ports on a panel.
1814 static int __devinit stl_initports(struct stlbrd *brdp, struct stlpanel *panelp)
1816 struct stlport *portp;
1820 pr_debug("stl_initports(brdp=%p,panelp=%p)\n", brdp, panelp);
1822 chipmask = stl_panelinit(brdp, panelp);
1825 * All UART's are initialized (if found!). Now go through and setup
1826 * each ports data structures.
1828 for (i = 0; i < panelp->nrports; i++) {
1829 portp = kzalloc(sizeof(struct stlport), GFP_KERNEL);
1831 printk("STALLION: failed to allocate memory "
1832 "(size=%Zd)\n", sizeof(struct stlport));
1836 portp->magic = STL_PORTMAGIC;
1838 portp->brdnr = panelp->brdnr;
1839 portp->panelnr = panelp->panelnr;
1840 portp->uartp = panelp->uartp;
1841 portp->clk = brdp->clk;
1842 portp->baud_base = STL_BAUDBASE;
1843 portp->close_delay = STL_CLOSEDELAY;
1844 portp->closing_wait = 30 * HZ;
1845 INIT_WORK(&portp->tqueue, stl_offintr);
1846 init_waitqueue_head(&portp->open_wait);
1847 init_waitqueue_head(&portp->close_wait);
1848 portp->stats.brd = portp->brdnr;
1849 portp->stats.panel = portp->panelnr;
1850 portp->stats.port = portp->portnr;
1851 panelp->ports[i] = portp;
1852 stl_portinit(brdp, panelp, portp);
1858 static void stl_cleanup_panels(struct stlbrd *brdp)
1860 struct stlpanel *panelp;
1861 struct stlport *portp;
1864 for (j = 0; j < STL_MAXPANELS; j++) {
1865 panelp = brdp->panels[j];
1868 for (k = 0; k < STL_PORTSPERPANEL; k++) {
1869 portp = panelp->ports[k];
1872 if (portp->tty != NULL)
1873 stl_hangup(portp->tty);
1874 kfree(portp->tx.buf);
1881 /*****************************************************************************/
1884 * Try to find and initialize an EasyIO board.
1887 static int __devinit stl_initeio(struct stlbrd *brdp)
1889 struct stlpanel *panelp;
1890 unsigned int status;
1894 pr_debug("stl_initeio(brdp=%p)\n", brdp);
1896 brdp->ioctrl = brdp->ioaddr1 + 1;
1897 brdp->iostatus = brdp->ioaddr1 + 2;
1899 status = inb(brdp->iostatus);
1900 if ((status & EIO_IDBITMASK) == EIO_MK3)
1904 * Handle board specific stuff now. The real difference is PCI
1907 if (brdp->brdtype == BRD_EASYIOPCI) {
1908 brdp->iosize1 = 0x80;
1909 brdp->iosize2 = 0x80;
1910 name = "serial(EIO-PCI)";
1911 outb(0x41, (brdp->ioaddr2 + 0x4c));
1914 name = "serial(EIO)";
1915 if ((brdp->irq < 0) || (brdp->irq > 15) ||
1916 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
1917 printk("STALLION: invalid irq=%d for brd=%d\n",
1918 brdp->irq, brdp->brdnr);
1922 outb((stl_vecmap[brdp->irq] | EIO_0WS |
1923 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
1928 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
1929 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
1930 "%x conflicts with another device\n", brdp->brdnr,
1935 if (brdp->iosize2 > 0)
1936 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
1937 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
1938 "address %x conflicts with another device\n",
1939 brdp->brdnr, brdp->ioaddr2);
1940 printk(KERN_WARNING "STALLION: Warning, also "
1941 "releasing board %d I/O address %x \n",
1942 brdp->brdnr, brdp->ioaddr1);
1947 * Everything looks OK, so let's go ahead and probe for the hardware.
1949 brdp->clk = CD1400_CLK;
1950 brdp->isr = stl_eiointr;
1953 switch (status & EIO_IDBITMASK) {
1955 brdp->clk = CD1400_CLK8M;
1965 switch (status & EIO_BRDMASK) {
1984 * We have verified that the board is actually present, so now we
1985 * can complete the setup.
1988 panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
1990 printk(KERN_WARNING "STALLION: failed to allocate memory "
1991 "(size=%Zd)\n", sizeof(struct stlpanel));
1996 panelp->magic = STL_PANELMAGIC;
1997 panelp->brdnr = brdp->brdnr;
1998 panelp->panelnr = 0;
1999 panelp->nrports = brdp->nrports;
2000 panelp->iobase = brdp->ioaddr1;
2001 panelp->hwid = status;
2002 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2003 panelp->uartp = &stl_sc26198uart;
2004 panelp->isr = stl_sc26198intr;
2006 panelp->uartp = &stl_cd1400uart;
2007 panelp->isr = stl_cd1400eiointr;
2010 brdp->panels[0] = panelp;
2012 brdp->state |= BRD_FOUND;
2013 brdp->hwid = status;
2014 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
2015 printk("STALLION: failed to register interrupt "
2016 "routine for %s irq=%d\n", name, brdp->irq);
2023 stl_cleanup_panels(brdp);
2025 if (brdp->iosize2 > 0)
2026 release_region(brdp->ioaddr2, brdp->iosize2);
2028 release_region(brdp->ioaddr1, brdp->iosize1);
2033 /*****************************************************************************/
2036 * Try to find an ECH board and initialize it. This code is capable of
2037 * dealing with all types of ECH board.
2040 static int __devinit stl_initech(struct stlbrd *brdp)
2042 struct stlpanel *panelp;
2043 unsigned int status, nxtid, ioaddr, conflict, panelnr, banknr, i;
2047 pr_debug("stl_initech(brdp=%p)\n", brdp);
2053 * Set up the initial board register contents for boards. This varies a
2054 * bit between the different board types. So we need to handle each
2055 * separately. Also do a check that the supplied IRQ is good.
2057 switch (brdp->brdtype) {
2060 brdp->isr = stl_echatintr;
2061 brdp->ioctrl = brdp->ioaddr1 + 1;
2062 brdp->iostatus = brdp->ioaddr1 + 1;
2063 status = inb(brdp->iostatus);
2064 if ((status & ECH_IDBITMASK) != ECH_ID) {
2068 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2069 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2070 printk("STALLION: invalid irq=%d for brd=%d\n",
2071 brdp->irq, brdp->brdnr);
2075 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2076 status |= (stl_vecmap[brdp->irq] << 1);
2077 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2078 brdp->ioctrlval = ECH_INTENABLE |
2079 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2080 for (i = 0; i < 10; i++)
2081 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2084 name = "serial(EC8/32)";
2085 outb(status, brdp->ioaddr1);
2089 brdp->isr = stl_echmcaintr;
2090 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2091 brdp->iostatus = brdp->ioctrl;
2092 status = inb(brdp->iostatus);
2093 if ((status & ECH_IDBITMASK) != ECH_ID) {
2097 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2098 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2099 printk("STALLION: invalid irq=%d for brd=%d\n",
2100 brdp->irq, brdp->brdnr);
2104 outb(ECHMC_BRDRESET, brdp->ioctrl);
2105 outb(ECHMC_INTENABLE, brdp->ioctrl);
2107 name = "serial(EC8/32-MC)";
2111 brdp->isr = stl_echpciintr;
2112 brdp->ioctrl = brdp->ioaddr1 + 2;
2115 name = "serial(EC8/32-PCI)";
2119 brdp->isr = stl_echpci64intr;
2120 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2121 outb(0x43, (brdp->ioaddr1 + 0x4c));
2122 brdp->iosize1 = 0x80;
2123 brdp->iosize2 = 0x80;
2124 name = "serial(EC8/64-PCI)";
2128 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
2134 * Check boards for possible IO address conflicts and return fail status
2135 * if an IO conflict found.
2138 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2139 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2140 "%x conflicts with another device\n", brdp->brdnr,
2145 if (brdp->iosize2 > 0)
2146 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2147 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2148 "address %x conflicts with another device\n",
2149 brdp->brdnr, brdp->ioaddr2);
2150 printk(KERN_WARNING "STALLION: Warning, also "
2151 "releasing board %d I/O address %x \n",
2152 brdp->brdnr, brdp->ioaddr1);
2157 * Scan through the secondary io address space looking for panels.
2158 * As we find'em allocate and initialize panel structures for each.
2160 brdp->clk = CD1400_CLK;
2161 brdp->hwid = status;
2163 ioaddr = brdp->ioaddr2;
2168 for (i = 0; i < STL_MAXPANELS; i++) {
2169 if (brdp->brdtype == BRD_ECHPCI) {
2170 outb(nxtid, brdp->ioctrl);
2171 ioaddr = brdp->ioaddr2;
2173 status = inb(ioaddr + ECH_PNLSTATUS);
2174 if ((status & ECH_PNLIDMASK) != nxtid)
2176 panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
2178 printk("STALLION: failed to allocate memory "
2179 "(size=%Zd)\n", sizeof(struct stlpanel));
2182 panelp->magic = STL_PANELMAGIC;
2183 panelp->brdnr = brdp->brdnr;
2184 panelp->panelnr = panelnr;
2185 panelp->iobase = ioaddr;
2186 panelp->pagenr = nxtid;
2187 panelp->hwid = status;
2188 brdp->bnk2panel[banknr] = panelp;
2189 brdp->bnkpageaddr[banknr] = nxtid;
2190 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2192 if (status & ECH_PNLXPID) {
2193 panelp->uartp = &stl_sc26198uart;
2194 panelp->isr = stl_sc26198intr;
2195 if (status & ECH_PNL16PORT) {
2196 panelp->nrports = 16;
2197 brdp->bnk2panel[banknr] = panelp;
2198 brdp->bnkpageaddr[banknr] = nxtid;
2199 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2202 panelp->nrports = 8;
2204 panelp->uartp = &stl_cd1400uart;
2205 panelp->isr = stl_cd1400echintr;
2206 if (status & ECH_PNL16PORT) {
2207 panelp->nrports = 16;
2208 panelp->ackmask = 0x80;
2209 if (brdp->brdtype != BRD_ECHPCI)
2210 ioaddr += EREG_BANKSIZE;
2211 brdp->bnk2panel[banknr] = panelp;
2212 brdp->bnkpageaddr[banknr] = ++nxtid;
2213 brdp->bnkstataddr[banknr++] = ioaddr +
2216 panelp->nrports = 8;
2217 panelp->ackmask = 0xc0;
2222 ioaddr += EREG_BANKSIZE;
2223 brdp->nrports += panelp->nrports;
2224 brdp->panels[panelnr++] = panelp;
2225 if ((brdp->brdtype != BRD_ECHPCI) &&
2226 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
2230 brdp->nrpanels = panelnr;
2231 brdp->nrbnks = banknr;
2232 if (brdp->brdtype == BRD_ECH)
2233 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2235 brdp->state |= BRD_FOUND;
2236 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
2237 printk("STALLION: failed to register interrupt "
2238 "routine for %s irq=%d\n", name, brdp->irq);
2245 stl_cleanup_panels(brdp);
2246 if (brdp->iosize2 > 0)
2247 release_region(brdp->ioaddr2, brdp->iosize2);
2249 release_region(brdp->ioaddr1, brdp->iosize1);
2254 /*****************************************************************************/
2257 * Initialize and configure the specified board.
2258 * Scan through all the boards in the configuration and see what we
2259 * can find. Handle EIO and the ECH boards a little differently here
2260 * since the initial search and setup is very different.
2263 static int __devinit stl_brdinit(struct stlbrd *brdp)
2267 pr_debug("stl_brdinit(brdp=%p)\n", brdp);
2269 switch (brdp->brdtype) {
2272 retval = stl_initeio(brdp);
2280 retval = stl_initech(brdp);
2285 printk("STALLION: board=%d is unknown board type=%d\n",
2286 brdp->brdnr, brdp->brdtype);
2291 if ((brdp->state & BRD_FOUND) == 0) {
2292 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2293 stl_brdnames[brdp->brdtype], brdp->brdnr,
2294 brdp->ioaddr1, brdp->irq);
2298 for (i = 0; i < STL_MAXPANELS; i++)
2299 if (brdp->panels[i] != NULL)
2300 stl_initports(brdp, brdp->panels[i]);
2302 printk("STALLION: %s found, board=%d io=%x irq=%d "
2303 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2304 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2309 free_irq(brdp->irq, brdp);
2311 stl_cleanup_panels(brdp);
2313 release_region(brdp->ioaddr1, brdp->iosize1);
2314 if (brdp->iosize2 > 0)
2315 release_region(brdp->ioaddr2, brdp->iosize2);
2320 /*****************************************************************************/
2323 * Find the next available board number that is free.
2326 static int __devinit stl_getbrdnr(void)
2330 for (i = 0; i < STL_MAXBRDS; i++)
2331 if (stl_brds[i] == NULL) {
2332 if (i >= stl_nrbrds)
2340 /*****************************************************************************/
2342 * We have a Stallion board. Allocate a board structure and
2343 * initialize it. Read its IO and IRQ resources from PCI
2344 * configuration space.
2347 static int __devinit stl_pciprobe(struct pci_dev *pdev,
2348 const struct pci_device_id *ent)
2350 struct stlbrd *brdp;
2351 unsigned int brdtype = ent->driver_data;
2352 int brdnr, retval = -ENODEV;
2354 if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2357 dev_info(&pdev->dev, "please, report this to LKML: %x/%x/%x\n",
2358 pdev->vendor, pdev->device, pdev->class);
2360 retval = pci_enable_device(pdev);
2363 brdp = stl_allocbrd();
2368 mutex_lock(&stl_brdslock);
2369 brdnr = stl_getbrdnr();
2371 dev_err(&pdev->dev, "too many boards found, "
2372 "maximum supported %d\n", STL_MAXBRDS);
2373 mutex_unlock(&stl_brdslock);
2376 brdp->brdnr = (unsigned int)brdnr;
2377 stl_brds[brdp->brdnr] = brdp;
2378 mutex_unlock(&stl_brdslock);
2380 brdp->brdtype = brdtype;
2381 brdp->state |= STL_PROBED;
2384 * We have all resources from the board, so let's setup the actual
2385 * board structure now.
2389 brdp->ioaddr2 = pci_resource_start(pdev, 0);
2390 brdp->ioaddr1 = pci_resource_start(pdev, 1);
2393 brdp->ioaddr2 = pci_resource_start(pdev, 2);
2394 brdp->ioaddr1 = pci_resource_start(pdev, 1);
2397 brdp->ioaddr1 = pci_resource_start(pdev, 2);
2398 brdp->ioaddr2 = pci_resource_start(pdev, 1);
2401 dev_err(&pdev->dev, "unknown PCI board type=%u\n", brdtype);
2405 brdp->irq = pdev->irq;
2406 retval = stl_brdinit(brdp);
2410 pci_set_drvdata(pdev, brdp);
2414 stl_brds[brdp->brdnr] = NULL;
2421 static void __devexit stl_pciremove(struct pci_dev *pdev)
2423 struct stlbrd *brdp = pci_get_drvdata(pdev);
2425 free_irq(brdp->irq, brdp);
2427 stl_cleanup_panels(brdp);
2429 release_region(brdp->ioaddr1, brdp->iosize1);
2430 if (brdp->iosize2 > 0)
2431 release_region(brdp->ioaddr2, brdp->iosize2);
2433 stl_brds[brdp->brdnr] = NULL;
2437 static struct pci_driver stl_pcidriver = {
2439 .id_table = stl_pcibrds,
2440 .probe = stl_pciprobe,
2441 .remove = __devexit_p(stl_pciremove)
2444 /*****************************************************************************/
2447 * Return the board stats structure to user app.
2450 static int stl_getbrdstats(combrd_t __user *bp)
2452 combrd_t stl_brdstats;
2453 struct stlbrd *brdp;
2454 struct stlpanel *panelp;
2457 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2459 if (stl_brdstats.brd >= STL_MAXBRDS)
2461 brdp = stl_brds[stl_brdstats.brd];
2465 memset(&stl_brdstats, 0, sizeof(combrd_t));
2466 stl_brdstats.brd = brdp->brdnr;
2467 stl_brdstats.type = brdp->brdtype;
2468 stl_brdstats.hwid = brdp->hwid;
2469 stl_brdstats.state = brdp->state;
2470 stl_brdstats.ioaddr = brdp->ioaddr1;
2471 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2472 stl_brdstats.irq = brdp->irq;
2473 stl_brdstats.nrpanels = brdp->nrpanels;
2474 stl_brdstats.nrports = brdp->nrports;
2475 for (i = 0; i < brdp->nrpanels; i++) {
2476 panelp = brdp->panels[i];
2477 stl_brdstats.panels[i].panel = i;
2478 stl_brdstats.panels[i].hwid = panelp->hwid;
2479 stl_brdstats.panels[i].nrports = panelp->nrports;
2482 return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
2485 /*****************************************************************************/
2488 * Resolve the referenced port number into a port struct pointer.
2491 static struct stlport *stl_getport(int brdnr, int panelnr, int portnr)
2493 struct stlbrd *brdp;
2494 struct stlpanel *panelp;
2496 if (brdnr < 0 || brdnr >= STL_MAXBRDS)
2498 brdp = stl_brds[brdnr];
2501 if (panelnr < 0 || (unsigned int)panelnr >= brdp->nrpanels)
2503 panelp = brdp->panels[panelnr];
2506 if (portnr < 0 || (unsigned int)portnr >= panelp->nrports)
2508 return panelp->ports[portnr];
2511 /*****************************************************************************/
2514 * Return the port stats structure to user app. A NULL port struct
2515 * pointer passed in means that we need to find out from the app
2516 * what port to get stats for (used through board control device).
2519 static int stl_getportstats(struct stlport *portp, comstats_t __user *cp)
2521 comstats_t stl_comstats;
2522 unsigned char *head, *tail;
2523 unsigned long flags;
2526 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2528 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2534 portp->stats.state = portp->istate;
2535 portp->stats.flags = portp->flags;
2536 portp->stats.hwid = portp->hwid;
2538 portp->stats.ttystate = 0;
2539 portp->stats.cflags = 0;
2540 portp->stats.iflags = 0;
2541 portp->stats.oflags = 0;
2542 portp->stats.lflags = 0;
2543 portp->stats.rxbuffered = 0;
2545 spin_lock_irqsave(&stallion_lock, flags);
2546 if (portp->tty != NULL)
2547 if (portp->tty->driver_data == portp) {
2548 portp->stats.ttystate = portp->tty->flags;
2549 /* No longer available as a statistic */
2550 portp->stats.rxbuffered = 1; /*portp->tty->flip.count; */
2551 if (portp->tty->termios != NULL) {
2552 portp->stats.cflags = portp->tty->termios->c_cflag;
2553 portp->stats.iflags = portp->tty->termios->c_iflag;
2554 portp->stats.oflags = portp->tty->termios->c_oflag;
2555 portp->stats.lflags = portp->tty->termios->c_lflag;
2558 spin_unlock_irqrestore(&stallion_lock, flags);
2560 head = portp->tx.head;
2561 tail = portp->tx.tail;
2562 portp->stats.txbuffered = (head >= tail) ? (head - tail) :
2563 (STL_TXBUFSIZE - (tail - head));
2565 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2567 return copy_to_user(cp, &portp->stats,
2568 sizeof(comstats_t)) ? -EFAULT : 0;
2571 /*****************************************************************************/
2574 * Clear the port stats structure. We also return it zeroed out...
2577 static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp)
2579 comstats_t stl_comstats;
2582 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2584 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2590 memset(&portp->stats, 0, sizeof(comstats_t));
2591 portp->stats.brd = portp->brdnr;
2592 portp->stats.panel = portp->panelnr;
2593 portp->stats.port = portp->portnr;
2594 return copy_to_user(cp, &portp->stats,
2595 sizeof(comstats_t)) ? -EFAULT : 0;
2598 /*****************************************************************************/
2601 * Return the entire driver ports structure to a user app.
2604 static int stl_getportstruct(struct stlport __user *arg)
2606 struct stlport stl_dummyport;
2607 struct stlport *portp;
2609 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
2611 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
2612 stl_dummyport.portnr);
2615 return copy_to_user(arg, portp, sizeof(struct stlport)) ? -EFAULT : 0;
2618 /*****************************************************************************/
2621 * Return the entire driver board structure to a user app.
2624 static int stl_getbrdstruct(struct stlbrd __user *arg)
2626 struct stlbrd stl_dummybrd;
2627 struct stlbrd *brdp;
2629 if (copy_from_user(&stl_dummybrd, arg, sizeof(struct stlbrd)))
2631 if (stl_dummybrd.brdnr >= STL_MAXBRDS)
2633 brdp = stl_brds[stl_dummybrd.brdnr];
2636 return copy_to_user(arg, brdp, sizeof(struct stlbrd)) ? -EFAULT : 0;
2639 /*****************************************************************************/
2642 * The "staliomem" device is also required to do some special operations
2643 * on the board and/or ports. In this driver it is mostly used for stats
2647 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
2650 void __user *argp = (void __user *)arg;
2652 pr_debug("stl_memioctl(ip=%p,fp=%p,cmd=%x,arg=%lx)\n", ip, fp, cmd,arg);
2655 if (brdnr >= STL_MAXBRDS)
2660 case COM_GETPORTSTATS:
2661 rc = stl_getportstats(NULL, argp);
2663 case COM_CLRPORTSTATS:
2664 rc = stl_clrportstats(NULL, argp);
2666 case COM_GETBRDSTATS:
2667 rc = stl_getbrdstats(argp);
2670 rc = stl_getportstruct(argp);
2673 rc = stl_getbrdstruct(argp);
2683 static const struct tty_operations stl_ops = {
2687 .put_char = stl_putchar,
2688 .flush_chars = stl_flushchars,
2689 .write_room = stl_writeroom,
2690 .chars_in_buffer = stl_charsinbuffer,
2692 .set_termios = stl_settermios,
2693 .throttle = stl_throttle,
2694 .unthrottle = stl_unthrottle,
2697 .hangup = stl_hangup,
2698 .flush_buffer = stl_flushbuffer,
2699 .break_ctl = stl_breakctl,
2700 .wait_until_sent = stl_waituntilsent,
2701 .send_xchar = stl_sendxchar,
2702 .read_proc = stl_readproc,
2703 .tiocmget = stl_tiocmget,
2704 .tiocmset = stl_tiocmset,
2707 /*****************************************************************************/
2708 /* CD1400 HARDWARE FUNCTIONS */
2709 /*****************************************************************************/
2712 * These functions get/set/update the registers of the cd1400 UARTs.
2713 * Access to the cd1400 registers is via an address/data io port pair.
2714 * (Maybe should make this inline...)
2717 static int stl_cd1400getreg(struct stlport *portp, int regnr)
2719 outb((regnr + portp->uartaddr), portp->ioaddr);
2720 return inb(portp->ioaddr + EREG_DATA);
2723 static void stl_cd1400setreg(struct stlport *portp, int regnr, int value)
2725 outb(regnr + portp->uartaddr, portp->ioaddr);
2726 outb(value, portp->ioaddr + EREG_DATA);
2729 static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value)
2731 outb(regnr + portp->uartaddr, portp->ioaddr);
2732 if (inb(portp->ioaddr + EREG_DATA) != value) {
2733 outb(value, portp->ioaddr + EREG_DATA);
2739 /*****************************************************************************/
2742 * Inbitialize the UARTs in a panel. We don't care what sort of board
2743 * these ports are on - since the port io registers are almost
2744 * identical when dealing with ports.
2747 static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
2751 int nrchips, uartaddr, ioaddr;
2752 unsigned long flags;
2754 pr_debug("stl_panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
2756 spin_lock_irqsave(&brd_lock, flags);
2757 BRDENABLE(panelp->brdnr, panelp->pagenr);
2760 * Check that each chip is present and started up OK.
2763 nrchips = panelp->nrports / CD1400_PORTS;
2764 for (i = 0; i < nrchips; i++) {
2765 if (brdp->brdtype == BRD_ECHPCI) {
2766 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
2767 ioaddr = panelp->iobase;
2769 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
2770 uartaddr = (i & 0x01) ? 0x080 : 0;
2771 outb((GFRCR + uartaddr), ioaddr);
2772 outb(0, (ioaddr + EREG_DATA));
2773 outb((CCR + uartaddr), ioaddr);
2774 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
2775 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
2776 outb((GFRCR + uartaddr), ioaddr);
2777 for (j = 0; j < CCR_MAXWAIT; j++)
2778 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
2781 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
2782 printk("STALLION: cd1400 not responding, "
2783 "brd=%d panel=%d chip=%d\n",
2784 panelp->brdnr, panelp->panelnr, i);
2787 chipmask |= (0x1 << i);
2788 outb((PPR + uartaddr), ioaddr);
2789 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
2792 BRDDISABLE(panelp->brdnr);
2793 spin_unlock_irqrestore(&brd_lock, flags);
2797 /*****************************************************************************/
2800 * Initialize hardware specific port registers.
2803 static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
2805 unsigned long flags;
2806 pr_debug("stl_cd1400portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
2809 if ((brdp == NULL) || (panelp == NULL) ||
2813 spin_lock_irqsave(&brd_lock, flags);
2814 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
2815 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
2816 portp->uartaddr = (portp->portnr & 0x04) << 5;
2817 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
2819 BRDENABLE(portp->brdnr, portp->pagenr);
2820 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2821 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
2822 portp->hwid = stl_cd1400getreg(portp, GFRCR);
2823 BRDDISABLE(portp->brdnr);
2824 spin_unlock_irqrestore(&brd_lock, flags);
2827 /*****************************************************************************/
2830 * Wait for the command register to be ready. We will poll this,
2831 * since it won't usually take too long to be ready.
2834 static void stl_cd1400ccrwait(struct stlport *portp)
2838 for (i = 0; i < CCR_MAXWAIT; i++)
2839 if (stl_cd1400getreg(portp, CCR) == 0)
2842 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
2843 portp->portnr, portp->panelnr, portp->brdnr);
2846 /*****************************************************************************/
2849 * Set up the cd1400 registers for a port based on the termios port
2853 static void stl_cd1400setport(struct stlport *portp, struct ktermios *tiosp)
2855 struct stlbrd *brdp;
2856 unsigned long flags;
2857 unsigned int clkdiv, baudrate;
2858 unsigned char cor1, cor2, cor3;
2859 unsigned char cor4, cor5, ccr;
2860 unsigned char srer, sreron, sreroff;
2861 unsigned char mcor1, mcor2, rtpr;
2862 unsigned char clk, div;
2878 brdp = stl_brds[portp->brdnr];
2883 * Set up the RX char ignore mask with those RX error types we
2884 * can ignore. We can get the cd1400 to help us out a little here,
2885 * it will ignore parity errors and breaks for us.
2887 portp->rxignoremsk = 0;
2888 if (tiosp->c_iflag & IGNPAR) {
2889 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
2890 cor1 |= COR1_PARIGNORE;
2892 if (tiosp->c_iflag & IGNBRK) {
2893 portp->rxignoremsk |= ST_BREAK;
2894 cor4 |= COR4_IGNBRK;
2897 portp->rxmarkmsk = ST_OVERRUN;
2898 if (tiosp->c_iflag & (INPCK | PARMRK))
2899 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
2900 if (tiosp->c_iflag & BRKINT)
2901 portp->rxmarkmsk |= ST_BREAK;
2904 * Go through the char size, parity and stop bits and set all the
2905 * option register appropriately.
2907 switch (tiosp->c_cflag & CSIZE) {
2922 if (tiosp->c_cflag & CSTOPB)
2927 if (tiosp->c_cflag & PARENB) {
2928 if (tiosp->c_cflag & PARODD)
2929 cor1 |= (COR1_PARENB | COR1_PARODD);
2931 cor1 |= (COR1_PARENB | COR1_PAREVEN);
2933 cor1 |= COR1_PARNONE;
2937 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
2938 * space for hardware flow control and the like. This should be set to
2939 * VMIN. Also here we will set the RX data timeout to 10ms - this should
2940 * really be based on VTIME.
2942 cor3 |= FIFO_RXTHRESHOLD;
2946 * Calculate the baud rate timers. For now we will just assume that
2947 * the input and output baud are the same. Could have used a baud
2948 * table here, but this way we can generate virtually any baud rate
2951 baudrate = tiosp->c_cflag & CBAUD;
2952 if (baudrate & CBAUDEX) {
2953 baudrate &= ~CBAUDEX;
2954 if ((baudrate < 1) || (baudrate > 4))
2955 tiosp->c_cflag &= ~CBAUDEX;
2959 baudrate = stl_baudrates[baudrate];
2960 if ((tiosp->c_cflag & CBAUD) == B38400) {
2961 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
2963 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
2965 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
2967 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
2969 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
2970 baudrate = (portp->baud_base / portp->custom_divisor);
2972 if (baudrate > STL_CD1400MAXBAUD)
2973 baudrate = STL_CD1400MAXBAUD;
2976 for (clk = 0; clk < CD1400_NUMCLKS; clk++) {
2977 clkdiv = (portp->clk / stl_cd1400clkdivs[clk]) / baudrate;
2981 div = (unsigned char) clkdiv;
2985 * Check what form of modem signaling is required and set it up.
2987 if ((tiosp->c_cflag & CLOCAL) == 0) {
2990 sreron |= SRER_MODEM;
2991 portp->flags |= ASYNC_CHECK_CD;
2993 portp->flags &= ~ASYNC_CHECK_CD;
2996 * Setup cd1400 enhanced modes if we can. In particular we want to
2997 * handle as much of the flow control as possible automatically. As
2998 * well as saving a few CPU cycles it will also greatly improve flow
2999 * control reliability.
3001 if (tiosp->c_iflag & IXON) {
3004 if (tiosp->c_iflag & IXANY)
3008 if (tiosp->c_cflag & CRTSCTS) {
3010 mcor1 |= FIFO_RTSTHRESHOLD;
3014 * All cd1400 register values calculated so go through and set
3018 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3019 portp->portnr, portp->panelnr, portp->brdnr);
3020 pr_debug(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3021 cor1, cor2, cor3, cor4, cor5);
3022 pr_debug(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3023 mcor1, mcor2, rtpr, sreron, sreroff);
3024 pr_debug(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3025 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3026 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3027 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3029 spin_lock_irqsave(&brd_lock, flags);
3030 BRDENABLE(portp->brdnr, portp->pagenr);
3031 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3032 srer = stl_cd1400getreg(portp, SRER);
3033 stl_cd1400setreg(portp, SRER, 0);
3034 if (stl_cd1400updatereg(portp, COR1, cor1))
3036 if (stl_cd1400updatereg(portp, COR2, cor2))
3038 if (stl_cd1400updatereg(portp, COR3, cor3))
3041 stl_cd1400ccrwait(portp);
3042 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3044 stl_cd1400setreg(portp, COR4, cor4);
3045 stl_cd1400setreg(portp, COR5, cor5);
3046 stl_cd1400setreg(portp, MCOR1, mcor1);
3047 stl_cd1400setreg(portp, MCOR2, mcor2);
3049 stl_cd1400setreg(portp, TCOR, clk);
3050 stl_cd1400setreg(portp, TBPR, div);
3051 stl_cd1400setreg(portp, RCOR, clk);
3052 stl_cd1400setreg(portp, RBPR, div);
3054 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3055 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3056 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3057 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3058 stl_cd1400setreg(portp, RTPR, rtpr);
3059 mcor1 = stl_cd1400getreg(portp, MSVR1);
3060 if (mcor1 & MSVR1_DCD)
3061 portp->sigs |= TIOCM_CD;
3063 portp->sigs &= ~TIOCM_CD;
3064 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3065 BRDDISABLE(portp->brdnr);
3066 spin_unlock_irqrestore(&brd_lock, flags);
3069 /*****************************************************************************/
3072 * Set the state of the DTR and RTS signals.
3075 static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts)
3077 unsigned char msvr1, msvr2;
3078 unsigned long flags;
3080 pr_debug("stl_cd1400setsignals(portp=%p,dtr=%d,rts=%d)\n",
3090 spin_lock_irqsave(&brd_lock, flags);
3091 BRDENABLE(portp->brdnr, portp->pagenr);
3092 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3094 stl_cd1400setreg(portp, MSVR2, msvr2);
3096 stl_cd1400setreg(portp, MSVR1, msvr1);
3097 BRDDISABLE(portp->brdnr);
3098 spin_unlock_irqrestore(&brd_lock, flags);
3101 /*****************************************************************************/
3104 * Return the state of the signals.
3107 static int stl_cd1400getsignals(struct stlport *portp)
3109 unsigned char msvr1, msvr2;
3110 unsigned long flags;
3113 pr_debug("stl_cd1400getsignals(portp=%p)\n", portp);
3115 spin_lock_irqsave(&brd_lock, flags);
3116 BRDENABLE(portp->brdnr, portp->pagenr);
3117 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3118 msvr1 = stl_cd1400getreg(portp, MSVR1);
3119 msvr2 = stl_cd1400getreg(portp, MSVR2);
3120 BRDDISABLE(portp->brdnr);
3121 spin_unlock_irqrestore(&brd_lock, flags);
3124 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3125 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3126 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3127 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3129 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3130 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3137 /*****************************************************************************/
3140 * Enable/Disable the Transmitter and/or Receiver.
3143 static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx)
3146 unsigned long flags;
3148 pr_debug("stl_cd1400enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
3153 ccr |= CCR_TXDISABLE;
3155 ccr |= CCR_TXENABLE;
3157 ccr |= CCR_RXDISABLE;
3159 ccr |= CCR_RXENABLE;
3161 spin_lock_irqsave(&brd_lock, flags);
3162 BRDENABLE(portp->brdnr, portp->pagenr);
3163 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3164 stl_cd1400ccrwait(portp);
3165 stl_cd1400setreg(portp, CCR, ccr);
3166 stl_cd1400ccrwait(portp);
3167 BRDDISABLE(portp->brdnr);
3168 spin_unlock_irqrestore(&brd_lock, flags);
3171 /*****************************************************************************/
3174 * Start/stop the Transmitter and/or Receiver.
3177 static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx)
3179 unsigned char sreron, sreroff;
3180 unsigned long flags;
3182 pr_debug("stl_cd1400startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
3187 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3189 sreron |= SRER_TXDATA;
3191 sreron |= SRER_TXEMPTY;
3193 sreroff |= SRER_RXDATA;
3195 sreron |= SRER_RXDATA;
3197 spin_lock_irqsave(&brd_lock, flags);
3198 BRDENABLE(portp->brdnr, portp->pagenr);
3199 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3200 stl_cd1400setreg(portp, SRER,
3201 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3202 BRDDISABLE(portp->brdnr);
3204 set_bit(ASYI_TXBUSY, &portp->istate);
3205 spin_unlock_irqrestore(&brd_lock, flags);
3208 /*****************************************************************************/
3211 * Disable all interrupts from this port.
3214 static void stl_cd1400disableintrs(struct stlport *portp)
3216 unsigned long flags;
3218 pr_debug("stl_cd1400disableintrs(portp=%p)\n", portp);
3220 spin_lock_irqsave(&brd_lock, flags);
3221 BRDENABLE(portp->brdnr, portp->pagenr);
3222 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3223 stl_cd1400setreg(portp, SRER, 0);
3224 BRDDISABLE(portp->brdnr);
3225 spin_unlock_irqrestore(&brd_lock, flags);
3228 /*****************************************************************************/
3230 static void stl_cd1400sendbreak(struct stlport *portp, int len)
3232 unsigned long flags;
3234 pr_debug("stl_cd1400sendbreak(portp=%p,len=%d)\n", portp, len);
3236 spin_lock_irqsave(&brd_lock, flags);
3237 BRDENABLE(portp->brdnr, portp->pagenr);
3238 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3239 stl_cd1400setreg(portp, SRER,
3240 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3242 BRDDISABLE(portp->brdnr);
3243 portp->brklen = len;
3245 portp->stats.txbreaks++;
3246 spin_unlock_irqrestore(&brd_lock, flags);
3249 /*****************************************************************************/
3252 * Take flow control actions...
3255 static void stl_cd1400flowctrl(struct stlport *portp, int state)
3257 struct tty_struct *tty;
3258 unsigned long flags;
3260 pr_debug("stl_cd1400flowctrl(portp=%p,state=%x)\n", portp, state);
3268 spin_lock_irqsave(&brd_lock, flags);
3269 BRDENABLE(portp->brdnr, portp->pagenr);
3270 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3273 if (tty->termios->c_iflag & IXOFF) {
3274 stl_cd1400ccrwait(portp);
3275 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3276 portp->stats.rxxon++;
3277 stl_cd1400ccrwait(portp);
3280 * Question: should we return RTS to what it was before? It may
3281 * have been set by an ioctl... Suppose not, since if you have
3282 * hardware flow control set then it is pretty silly to go and
3283 * set the RTS line by hand.
3285 if (tty->termios->c_cflag & CRTSCTS) {
3286 stl_cd1400setreg(portp, MCOR1,
3287 (stl_cd1400getreg(portp, MCOR1) |
3288 FIFO_RTSTHRESHOLD));
3289 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3290 portp->stats.rxrtson++;
3293 if (tty->termios->c_iflag & IXOFF) {
3294 stl_cd1400ccrwait(portp);
3295 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3296 portp->stats.rxxoff++;
3297 stl_cd1400ccrwait(portp);
3299 if (tty->termios->c_cflag & CRTSCTS) {
3300 stl_cd1400setreg(portp, MCOR1,
3301 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3302 stl_cd1400setreg(portp, MSVR2, 0);
3303 portp->stats.rxrtsoff++;
3307 BRDDISABLE(portp->brdnr);
3308 spin_unlock_irqrestore(&brd_lock, flags);
3311 /*****************************************************************************/
3314 * Send a flow control character...
3317 static void stl_cd1400sendflow(struct stlport *portp, int state)
3319 struct tty_struct *tty;
3320 unsigned long flags;
3322 pr_debug("stl_cd1400sendflow(portp=%p,state=%x)\n", portp, state);
3330 spin_lock_irqsave(&brd_lock, flags);
3331 BRDENABLE(portp->brdnr, portp->pagenr);
3332 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3334 stl_cd1400ccrwait(portp);
3335 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3336 portp->stats.rxxon++;
3337 stl_cd1400ccrwait(portp);
3339 stl_cd1400ccrwait(portp);
3340 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3341 portp->stats.rxxoff++;
3342 stl_cd1400ccrwait(portp);
3344 BRDDISABLE(portp->brdnr);
3345 spin_unlock_irqrestore(&brd_lock, flags);
3348 /*****************************************************************************/
3350 static void stl_cd1400flush(struct stlport *portp)
3352 unsigned long flags;
3354 pr_debug("stl_cd1400flush(portp=%p)\n", portp);
3359 spin_lock_irqsave(&brd_lock, flags);
3360 BRDENABLE(portp->brdnr, portp->pagenr);
3361 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3362 stl_cd1400ccrwait(portp);
3363 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3364 stl_cd1400ccrwait(portp);
3365 portp->tx.tail = portp->tx.head;
3366 BRDDISABLE(portp->brdnr);
3367 spin_unlock_irqrestore(&brd_lock, flags);
3370 /*****************************************************************************/
3373 * Return the current state of data flow on this port. This is only
3374 * really interresting when determining if data has fully completed
3375 * transmission or not... This is easy for the cd1400, it accurately
3376 * maintains the busy port flag.
3379 static int stl_cd1400datastate(struct stlport *portp)
3381 pr_debug("stl_cd1400datastate(portp=%p)\n", portp);
3386 return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
3389 /*****************************************************************************/
3392 * Interrupt service routine for cd1400 EasyIO boards.
3395 static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase)
3397 unsigned char svrtype;
3399 pr_debug("stl_cd1400eiointr(panelp=%p,iobase=%x)\n", panelp, iobase);
3401 spin_lock(&brd_lock);
3403 svrtype = inb(iobase + EREG_DATA);
3404 if (panelp->nrports > 4) {
3405 outb((SVRR + 0x80), iobase);
3406 svrtype |= inb(iobase + EREG_DATA);
3409 if (svrtype & SVRR_RX)
3410 stl_cd1400rxisr(panelp, iobase);
3411 else if (svrtype & SVRR_TX)
3412 stl_cd1400txisr(panelp, iobase);
3413 else if (svrtype & SVRR_MDM)
3414 stl_cd1400mdmisr(panelp, iobase);
3416 spin_unlock(&brd_lock);
3419 /*****************************************************************************/
3422 * Interrupt service routine for cd1400 panels.
3425 static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase)
3427 unsigned char svrtype;
3429 pr_debug("stl_cd1400echintr(panelp=%p,iobase=%x)\n", panelp, iobase);
3432 svrtype = inb(iobase + EREG_DATA);
3433 outb((SVRR + 0x80), iobase);
3434 svrtype |= inb(iobase + EREG_DATA);
3435 if (svrtype & SVRR_RX)
3436 stl_cd1400rxisr(panelp, iobase);
3437 else if (svrtype & SVRR_TX)
3438 stl_cd1400txisr(panelp, iobase);
3439 else if (svrtype & SVRR_MDM)
3440 stl_cd1400mdmisr(panelp, iobase);
3444 /*****************************************************************************/
3447 * Unfortunately we need to handle breaks in the TX data stream, since
3448 * this is the only way to generate them on the cd1400.
3451 static int stl_cd1400breakisr(struct stlport *portp, int ioaddr)
3453 if (portp->brklen == 1) {
3454 outb((COR2 + portp->uartaddr), ioaddr);
3455 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
3456 (ioaddr + EREG_DATA));
3457 outb((TDR + portp->uartaddr), ioaddr);
3458 outb(ETC_CMD, (ioaddr + EREG_DATA));
3459 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
3460 outb((SRER + portp->uartaddr), ioaddr);
3461 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
3462 (ioaddr + EREG_DATA));
3464 } else if (portp->brklen > 1) {
3465 outb((TDR + portp->uartaddr), ioaddr);
3466 outb(ETC_CMD, (ioaddr + EREG_DATA));
3467 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
3471 outb((COR2 + portp->uartaddr), ioaddr);
3472 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
3473 (ioaddr + EREG_DATA));
3479 /*****************************************************************************/
3482 * Transmit interrupt handler. This has gotta be fast! Handling TX
3483 * chars is pretty simple, stuff as many as possible from the TX buffer
3484 * into the cd1400 FIFO. Must also handle TX breaks here, since they
3485 * are embedded as commands in the data stream. Oh no, had to use a goto!
3486 * This could be optimized more, will do when I get time...
3487 * In practice it is possible that interrupts are enabled but that the
3488 * port has been hung up. Need to handle not having any TX buffer here,
3489 * this is done by using the side effect that head and tail will also
3490 * be NULL if the buffer has been freed.
3493 static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr)
3495 struct stlport *portp;
3498 unsigned char ioack, srer;
3500 pr_debug("stl_cd1400txisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3502 ioack = inb(ioaddr + EREG_TXACK);
3503 if (((ioack & panelp->ackmask) != 0) ||
3504 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
3505 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
3508 portp = panelp->ports[(ioack >> 3)];
3511 * Unfortunately we need to handle breaks in the data stream, since
3512 * this is the only way to generate them on the cd1400. Do it now if
3513 * a break is to be sent.
3515 if (portp->brklen != 0)
3516 if (stl_cd1400breakisr(portp, ioaddr))
3519 head = portp->tx.head;
3520 tail = portp->tx.tail;
3521 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
3522 if ((len == 0) || ((len < STL_TXBUFLOW) &&
3523 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
3524 set_bit(ASYI_TXLOW, &portp->istate);
3525 schedule_work(&portp->tqueue);
3529 outb((SRER + portp->uartaddr), ioaddr);
3530 srer = inb(ioaddr + EREG_DATA);
3531 if (srer & SRER_TXDATA) {
3532 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
3534 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
3535 clear_bit(ASYI_TXBUSY, &portp->istate);
3537 outb(srer, (ioaddr + EREG_DATA));
3539 len = min(len, CD1400_TXFIFOSIZE);
3540 portp->stats.txtotal += len;
3541 stlen = min(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
3542 outb((TDR + portp->uartaddr), ioaddr);
3543 outsb((ioaddr + EREG_DATA), tail, stlen);
3546 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
3547 tail = portp->tx.buf;
3549 outsb((ioaddr + EREG_DATA), tail, len);
3552 portp->tx.tail = tail;
3556 outb((EOSRR + portp->uartaddr), ioaddr);
3557 outb(0, (ioaddr + EREG_DATA));
3560 /*****************************************************************************/
3563 * Receive character interrupt handler. Determine if we have good chars
3564 * or bad chars and then process appropriately. Good chars are easy
3565 * just shove the lot into the RX buffer and set all status byte to 0.
3566 * If a bad RX char then process as required. This routine needs to be
3567 * fast! In practice it is possible that we get an interrupt on a port
3568 * that is closed. This can happen on hangups - since they completely
3569 * shutdown a port not in user context. Need to handle this case.
3572 static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr)
3574 struct stlport *portp;
3575 struct tty_struct *tty;
3576 unsigned int ioack, len, buflen;
3577 unsigned char status;
3580 pr_debug("stl_cd1400rxisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3582 ioack = inb(ioaddr + EREG_RXACK);
3583 if ((ioack & panelp->ackmask) != 0) {
3584 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
3587 portp = panelp->ports[(ioack >> 3)];
3590 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
3591 outb((RDCR + portp->uartaddr), ioaddr);
3592 len = inb(ioaddr + EREG_DATA);
3593 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
3594 len = min(len, sizeof(stl_unwanted));
3595 outb((RDSR + portp->uartaddr), ioaddr);
3596 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
3597 portp->stats.rxlost += len;
3598 portp->stats.rxtotal += len;
3600 len = min(len, buflen);
3603 outb((RDSR + portp->uartaddr), ioaddr);
3604 tty_prepare_flip_string(tty, &ptr, len);
3605 insb((ioaddr + EREG_DATA), ptr, len);
3606 tty_schedule_flip(tty);
3607 portp->stats.rxtotal += len;
3610 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
3611 outb((RDSR + portp->uartaddr), ioaddr);
3612 status = inb(ioaddr + EREG_DATA);
3613 ch = inb(ioaddr + EREG_DATA);
3614 if (status & ST_PARITY)
3615 portp->stats.rxparity++;
3616 if (status & ST_FRAMING)
3617 portp->stats.rxframing++;
3618 if (status & ST_OVERRUN)
3619 portp->stats.rxoverrun++;
3620 if (status & ST_BREAK)
3621 portp->stats.rxbreaks++;
3622 if (status & ST_SCHARMASK) {
3623 if ((status & ST_SCHARMASK) == ST_SCHAR1)
3624 portp->stats.txxon++;
3625 if ((status & ST_SCHARMASK) == ST_SCHAR2)
3626 portp->stats.txxoff++;
3629 if (tty != NULL && (portp->rxignoremsk & status) == 0) {
3630 if (portp->rxmarkmsk & status) {
3631 if (status & ST_BREAK) {
3633 if (portp->flags & ASYNC_SAK) {
3635 BRDENABLE(portp->brdnr, portp->pagenr);
3637 } else if (status & ST_PARITY)
3638 status = TTY_PARITY;
3639 else if (status & ST_FRAMING)
3641 else if(status & ST_OVERRUN)
3642 status = TTY_OVERRUN;
3647 tty_insert_flip_char(tty, ch, status);
3648 tty_schedule_flip(tty);
3651 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
3656 outb((EOSRR + portp->uartaddr), ioaddr);
3657 outb(0, (ioaddr + EREG_DATA));
3660 /*****************************************************************************/
3663 * Modem interrupt handler. The is called when the modem signal line
3664 * (DCD) has changed state. Leave most of the work to the off-level
3665 * processing routine.
3668 static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr)
3670 struct stlport *portp;
3674 pr_debug("stl_cd1400mdmisr(panelp=%p)\n", panelp);
3676 ioack = inb(ioaddr + EREG_MDACK);
3677 if (((ioack & panelp->ackmask) != 0) ||
3678 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
3679 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
3682 portp = panelp->ports[(ioack >> 3)];
3684 outb((MISR + portp->uartaddr), ioaddr);
3685 misr = inb(ioaddr + EREG_DATA);
3686 if (misr & MISR_DCD) {
3687 set_bit(ASYI_DCDCHANGE, &portp->istate);
3688 schedule_work(&portp->tqueue);
3689 portp->stats.modem++;
3692 outb((EOSRR + portp->uartaddr), ioaddr);
3693 outb(0, (ioaddr + EREG_DATA));
3696 /*****************************************************************************/
3697 /* SC26198 HARDWARE FUNCTIONS */
3698 /*****************************************************************************/
3701 * These functions get/set/update the registers of the sc26198 UARTs.
3702 * Access to the sc26198 registers is via an address/data io port pair.
3703 * (Maybe should make this inline...)
3706 static int stl_sc26198getreg(struct stlport *portp, int regnr)
3708 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3709 return inb(portp->ioaddr + XP_DATA);
3712 static void stl_sc26198setreg(struct stlport *portp, int regnr, int value)
3714 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3715 outb(value, (portp->ioaddr + XP_DATA));
3718 static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value)
3720 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3721 if (inb(portp->ioaddr + XP_DATA) != value) {
3722 outb(value, (portp->ioaddr + XP_DATA));
3728 /*****************************************************************************/
3731 * Functions to get and set the sc26198 global registers.
3734 static int stl_sc26198getglobreg(struct stlport *portp, int regnr)
3736 outb(regnr, (portp->ioaddr + XP_ADDR));
3737 return inb(portp->ioaddr + XP_DATA);
3741 static void stl_sc26198setglobreg(struct stlport *portp, int regnr, int value)
3743 outb(regnr, (portp->ioaddr + XP_ADDR));
3744 outb(value, (portp->ioaddr + XP_DATA));
3748 /*****************************************************************************/
3751 * Inbitialize the UARTs in a panel. We don't care what sort of board
3752 * these ports are on - since the port io registers are almost
3753 * identical when dealing with ports.
3756 static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
3759 int nrchips, ioaddr;
3761 pr_debug("stl_sc26198panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
3763 BRDENABLE(panelp->brdnr, panelp->pagenr);
3766 * Check that each chip is present and started up OK.
3769 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
3770 if (brdp->brdtype == BRD_ECHPCI)
3771 outb(panelp->pagenr, brdp->ioctrl);
3773 for (i = 0; i < nrchips; i++) {
3774 ioaddr = panelp->iobase + (i * 4);
3775 outb(SCCR, (ioaddr + XP_ADDR));
3776 outb(CR_RESETALL, (ioaddr + XP_DATA));
3777 outb(TSTR, (ioaddr + XP_ADDR));
3778 if (inb(ioaddr + XP_DATA) != 0) {
3779 printk("STALLION: sc26198 not responding, "
3780 "brd=%d panel=%d chip=%d\n",
3781 panelp->brdnr, panelp->panelnr, i);
3784 chipmask |= (0x1 << i);
3785 outb(GCCR, (ioaddr + XP_ADDR));
3786 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
3787 outb(WDTRCR, (ioaddr + XP_ADDR));
3788 outb(0xff, (ioaddr + XP_DATA));
3791 BRDDISABLE(panelp->brdnr);
3795 /*****************************************************************************/
3798 * Initialize hardware specific port registers.
3801 static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
3803 pr_debug("stl_sc26198portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
3806 if ((brdp == NULL) || (panelp == NULL) ||
3810 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
3811 portp->uartaddr = (portp->portnr & 0x07) << 4;
3812 portp->pagenr = panelp->pagenr;
3815 BRDENABLE(portp->brdnr, portp->pagenr);
3816 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
3817 BRDDISABLE(portp->brdnr);
3820 /*****************************************************************************/
3823 * Set up the sc26198 registers for a port based on the termios port
3827 static void stl_sc26198setport(struct stlport *portp, struct ktermios *tiosp)
3829 struct stlbrd *brdp;
3830 unsigned long flags;
3831 unsigned int baudrate;
3832 unsigned char mr0, mr1, mr2, clk;
3833 unsigned char imron, imroff, iopr, ipr;
3843 brdp = stl_brds[portp->brdnr];
3848 * Set up the RX char ignore mask with those RX error types we
3851 portp->rxignoremsk = 0;
3852 if (tiosp->c_iflag & IGNPAR)
3853 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
3855 if (tiosp->c_iflag & IGNBRK)
3856 portp->rxignoremsk |= SR_RXBREAK;
3858 portp->rxmarkmsk = SR_RXOVERRUN;
3859 if (tiosp->c_iflag & (INPCK | PARMRK))
3860 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
3861 if (tiosp->c_iflag & BRKINT)
3862 portp->rxmarkmsk |= SR_RXBREAK;
3865 * Go through the char size, parity and stop bits and set all the
3866 * option register appropriately.
3868 switch (tiosp->c_cflag & CSIZE) {
3883 if (tiosp->c_cflag & CSTOPB)
3888 if (tiosp->c_cflag & PARENB) {
3889 if (tiosp->c_cflag & PARODD)
3890 mr1 |= (MR1_PARENB | MR1_PARODD);
3892 mr1 |= (MR1_PARENB | MR1_PAREVEN);
3896 mr1 |= MR1_ERRBLOCK;
3899 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
3900 * space for hardware flow control and the like. This should be set to
3903 mr2 |= MR2_RXFIFOHALF;
3906 * Calculate the baud rate timers. For now we will just assume that
3907 * the input and output baud are the same. The sc26198 has a fixed
3908 * baud rate table, so only discrete baud rates possible.
3910 baudrate = tiosp->c_cflag & CBAUD;
3911 if (baudrate & CBAUDEX) {
3912 baudrate &= ~CBAUDEX;
3913 if ((baudrate < 1) || (baudrate > 4))
3914 tiosp->c_cflag &= ~CBAUDEX;
3918 baudrate = stl_baudrates[baudrate];
3919 if ((tiosp->c_cflag & CBAUD) == B38400) {
3920 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3922 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3924 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3926 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3928 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3929 baudrate = (portp->baud_base / portp->custom_divisor);
3931 if (baudrate > STL_SC26198MAXBAUD)
3932 baudrate = STL_SC26198MAXBAUD;
3935 for (clk = 0; clk < SC26198_NRBAUDS; clk++)
3936 if (baudrate <= sc26198_baudtable[clk])
3940 * Check what form of modem signaling is required and set it up.
3942 if (tiosp->c_cflag & CLOCAL) {
3943 portp->flags &= ~ASYNC_CHECK_CD;
3945 iopr |= IOPR_DCDCOS;
3947 portp->flags |= ASYNC_CHECK_CD;
3951 * Setup sc26198 enhanced modes if we can. In particular we want to
3952 * handle as much of the flow control as possible automatically. As
3953 * well as saving a few CPU cycles it will also greatly improve flow
3954 * control reliability.
3956 if (tiosp->c_iflag & IXON) {
3957 mr0 |= MR0_SWFTX | MR0_SWFT;
3958 imron |= IR_XONXOFF;
3960 imroff |= IR_XONXOFF;
3962 if (tiosp->c_iflag & IXOFF)
3965 if (tiosp->c_cflag & CRTSCTS) {
3971 * All sc26198 register values calculated so go through and set
3975 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3976 portp->portnr, portp->panelnr, portp->brdnr);
3977 pr_debug(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
3978 pr_debug(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
3979 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3980 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3981 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3983 spin_lock_irqsave(&brd_lock, flags);
3984 BRDENABLE(portp->brdnr, portp->pagenr);
3985 stl_sc26198setreg(portp, IMR, 0);
3986 stl_sc26198updatereg(portp, MR0, mr0);
3987 stl_sc26198updatereg(portp, MR1, mr1);
3988 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
3989 stl_sc26198updatereg(portp, MR2, mr2);
3990 stl_sc26198updatereg(portp, IOPIOR,
3991 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
3994 stl_sc26198setreg(portp, TXCSR, clk);
3995 stl_sc26198setreg(portp, RXCSR, clk);
3998 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
3999 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4001 ipr = stl_sc26198getreg(portp, IPR);
4003 portp->sigs &= ~TIOCM_CD;
4005 portp->sigs |= TIOCM_CD;
4007 portp->imr = (portp->imr & ~imroff) | imron;
4008 stl_sc26198setreg(portp, IMR, portp->imr);
4009 BRDDISABLE(portp->brdnr);
4010 spin_unlock_irqrestore(&brd_lock, flags);
4013 /*****************************************************************************/
4016 * Set the state of the DTR and RTS signals.
4019 static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts)
4021 unsigned char iopioron, iopioroff;
4022 unsigned long flags;
4024 pr_debug("stl_sc26198setsignals(portp=%p,dtr=%d,rts=%d)\n", portp,
4030 iopioroff |= IPR_DTR;
4032 iopioron |= IPR_DTR;
4034 iopioroff |= IPR_RTS;
4036 iopioron |= IPR_RTS;
4038 spin_lock_irqsave(&brd_lock, flags);
4039 BRDENABLE(portp->brdnr, portp->pagenr);
4040 stl_sc26198setreg(portp, IOPIOR,
4041 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4042 BRDDISABLE(portp->brdnr);
4043 spin_unlock_irqrestore(&brd_lock, flags);
4046 /*****************************************************************************/
4049 * Return the state of the signals.
4052 static int stl_sc26198getsignals(struct stlport *portp)
4055 unsigned long flags;
4058 pr_debug("stl_sc26198getsignals(portp=%p)\n", portp);
4060 spin_lock_irqsave(&brd_lock, flags);
4061 BRDENABLE(portp->brdnr, portp->pagenr);
4062 ipr = stl_sc26198getreg(portp, IPR);
4063 BRDDISABLE(portp->brdnr);
4064 spin_unlock_irqrestore(&brd_lock, flags);
4067 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4068 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4069 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4070 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4075 /*****************************************************************************/
4078 * Enable/Disable the Transmitter and/or Receiver.
4081 static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx)
4084 unsigned long flags;
4086 pr_debug("stl_sc26198enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx,tx);
4088 ccr = portp->crenable;
4090 ccr &= ~CR_TXENABLE;
4094 ccr &= ~CR_RXENABLE;
4098 spin_lock_irqsave(&brd_lock, flags);
4099 BRDENABLE(portp->brdnr, portp->pagenr);
4100 stl_sc26198setreg(portp, SCCR, ccr);
4101 BRDDISABLE(portp->brdnr);
4102 portp->crenable = ccr;
4103 spin_unlock_irqrestore(&brd_lock, flags);
4106 /*****************************************************************************/
4109 * Start/stop the Transmitter and/or Receiver.
4112 static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx)
4115 unsigned long flags;
4117 pr_debug("stl_sc26198startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
4125 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4127 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4129 spin_lock_irqsave(&brd_lock, flags);
4130 BRDENABLE(portp->brdnr, portp->pagenr);
4131 stl_sc26198setreg(portp, IMR, imr);
4132 BRDDISABLE(portp->brdnr);
4135 set_bit(ASYI_TXBUSY, &portp->istate);
4136 spin_unlock_irqrestore(&brd_lock, flags);
4139 /*****************************************************************************/
4142 * Disable all interrupts from this port.
4145 static void stl_sc26198disableintrs(struct stlport *portp)
4147 unsigned long flags;
4149 pr_debug("stl_sc26198disableintrs(portp=%p)\n", portp);
4151 spin_lock_irqsave(&brd_lock, flags);
4152 BRDENABLE(portp->brdnr, portp->pagenr);
4154 stl_sc26198setreg(portp, IMR, 0);
4155 BRDDISABLE(portp->brdnr);
4156 spin_unlock_irqrestore(&brd_lock, flags);
4159 /*****************************************************************************/
4161 static void stl_sc26198sendbreak(struct stlport *portp, int len)
4163 unsigned long flags;
4165 pr_debug("stl_sc26198sendbreak(portp=%p,len=%d)\n", portp, len);
4167 spin_lock_irqsave(&brd_lock, flags);
4168 BRDENABLE(portp->brdnr, portp->pagenr);
4170 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4171 portp->stats.txbreaks++;
4173 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4175 BRDDISABLE(portp->brdnr);
4176 spin_unlock_irqrestore(&brd_lock, flags);
4179 /*****************************************************************************/
4182 * Take flow control actions...
4185 static void stl_sc26198flowctrl(struct stlport *portp, int state)
4187 struct tty_struct *tty;
4188 unsigned long flags;
4191 pr_debug("stl_sc26198flowctrl(portp=%p,state=%x)\n", portp, state);
4199 spin_lock_irqsave(&brd_lock, flags);
4200 BRDENABLE(portp->brdnr, portp->pagenr);
4203 if (tty->termios->c_iflag & IXOFF) {
4204 mr0 = stl_sc26198getreg(portp, MR0);
4205 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4206 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4208 portp->stats.rxxon++;
4209 stl_sc26198wait(portp);
4210 stl_sc26198setreg(portp, MR0, mr0);
4213 * Question: should we return RTS to what it was before? It may
4214 * have been set by an ioctl... Suppose not, since if you have
4215 * hardware flow control set then it is pretty silly to go and
4216 * set the RTS line by hand.
4218 if (tty->termios->c_cflag & CRTSCTS) {
4219 stl_sc26198setreg(portp, MR1,
4220 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4221 stl_sc26198setreg(portp, IOPIOR,
4222 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4223 portp->stats.rxrtson++;
4226 if (tty->termios->c_iflag & IXOFF) {
4227 mr0 = stl_sc26198getreg(portp, MR0);
4228 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4229 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4231 portp->stats.rxxoff++;
4232 stl_sc26198wait(portp);
4233 stl_sc26198setreg(portp, MR0, mr0);
4235 if (tty->termios->c_cflag & CRTSCTS) {
4236 stl_sc26198setreg(portp, MR1,
4237 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4238 stl_sc26198setreg(portp, IOPIOR,
4239 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4240 portp->stats.rxrtsoff++;
4244 BRDDISABLE(portp->brdnr);
4245 spin_unlock_irqrestore(&brd_lock, flags);
4248 /*****************************************************************************/
4251 * Send a flow control character.
4254 static void stl_sc26198sendflow(struct stlport *portp, int state)
4256 struct tty_struct *tty;
4257 unsigned long flags;
4260 pr_debug("stl_sc26198sendflow(portp=%p,state=%x)\n", portp, state);
4268 spin_lock_irqsave(&brd_lock, flags);
4269 BRDENABLE(portp->brdnr, portp->pagenr);
4271 mr0 = stl_sc26198getreg(portp, MR0);
4272 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4273 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4275 portp->stats.rxxon++;
4276 stl_sc26198wait(portp);
4277 stl_sc26198setreg(portp, MR0, mr0);
4279 mr0 = stl_sc26198getreg(portp, MR0);
4280 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4281 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4283 portp->stats.rxxoff++;
4284 stl_sc26198wait(portp);
4285 stl_sc26198setreg(portp, MR0, mr0);
4287 BRDDISABLE(portp->brdnr);
4288 spin_unlock_irqrestore(&brd_lock, flags);
4291 /*****************************************************************************/
4293 static void stl_sc26198flush(struct stlport *portp)
4295 unsigned long flags;
4297 pr_debug("stl_sc26198flush(portp=%p)\n", portp);
4302 spin_lock_irqsave(&brd_lock, flags);
4303 BRDENABLE(portp->brdnr, portp->pagenr);
4304 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4305 stl_sc26198setreg(portp, SCCR, portp->crenable);
4306 BRDDISABLE(portp->brdnr);
4307 portp->tx.tail = portp->tx.head;
4308 spin_unlock_irqrestore(&brd_lock, flags);
4311 /*****************************************************************************/
4314 * Return the current state of data flow on this port. This is only
4315 * really interresting when determining if data has fully completed
4316 * transmission or not... The sc26198 interrupt scheme cannot
4317 * determine when all data has actually drained, so we need to
4318 * check the port statusy register to be sure.
4321 static int stl_sc26198datastate(struct stlport *portp)
4323 unsigned long flags;
4326 pr_debug("stl_sc26198datastate(portp=%p)\n", portp);
4330 if (test_bit(ASYI_TXBUSY, &portp->istate))
4333 spin_lock_irqsave(&brd_lock, flags);
4334 BRDENABLE(portp->brdnr, portp->pagenr);
4335 sr = stl_sc26198getreg(portp, SR);
4336 BRDDISABLE(portp->brdnr);
4337 spin_unlock_irqrestore(&brd_lock, flags);
4339 return (sr & SR_TXEMPTY) ? 0 : 1;
4342 /*****************************************************************************/
4345 * Delay for a small amount of time, to give the sc26198 a chance
4346 * to process a command...
4349 static void stl_sc26198wait(struct stlport *portp)
4353 pr_debug("stl_sc26198wait(portp=%p)\n", portp);
4358 for (i = 0; i < 20; i++)
4359 stl_sc26198getglobreg(portp, TSTR);
4362 /*****************************************************************************/
4365 * If we are TX flow controlled and in IXANY mode then we may
4366 * need to unflow control here. We gotta do this because of the
4367 * automatic flow control modes of the sc26198.
4370 static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty)
4374 mr0 = stl_sc26198getreg(portp, MR0);
4375 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4376 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4377 stl_sc26198wait(portp);
4378 stl_sc26198setreg(portp, MR0, mr0);
4379 clear_bit(ASYI_TXFLOWED, &portp->istate);
4382 /*****************************************************************************/
4385 * Interrupt service routine for sc26198 panels.
4388 static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase)
4390 struct stlport *portp;
4393 spin_lock(&brd_lock);
4396 * Work around bug in sc26198 chip... Cannot have A6 address
4397 * line of UART high, else iack will be returned as 0.
4399 outb(0, (iobase + 1));
4401 iack = inb(iobase + XP_IACK);
4402 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4404 if (iack & IVR_RXDATA)
4405 stl_sc26198rxisr(portp, iack);
4406 else if (iack & IVR_TXDATA)
4407 stl_sc26198txisr(portp);
4409 stl_sc26198otherisr(portp, iack);
4411 spin_unlock(&brd_lock);
4414 /*****************************************************************************/
4417 * Transmit interrupt handler. This has gotta be fast! Handling TX
4418 * chars is pretty simple, stuff as many as possible from the TX buffer
4419 * into the sc26198 FIFO.
4420 * In practice it is possible that interrupts are enabled but that the
4421 * port has been hung up. Need to handle not having any TX buffer here,
4422 * this is done by using the side effect that head and tail will also
4423 * be NULL if the buffer has been freed.
4426 static void stl_sc26198txisr(struct stlport *portp)
4428 unsigned int ioaddr;
4433 pr_debug("stl_sc26198txisr(portp=%p)\n", portp);
4435 ioaddr = portp->ioaddr;
4436 head = portp->tx.head;
4437 tail = portp->tx.tail;
4438 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4439 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4440 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4441 set_bit(ASYI_TXLOW, &portp->istate);
4442 schedule_work(&portp->tqueue);
4446 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
4447 mr0 = inb(ioaddr + XP_DATA);
4448 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4449 portp->imr &= ~IR_TXRDY;
4450 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
4451 outb(portp->imr, (ioaddr + XP_DATA));
4452 clear_bit(ASYI_TXBUSY, &portp->istate);
4454 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4455 outb(mr0, (ioaddr + XP_DATA));
4458 len = min(len, SC26198_TXFIFOSIZE);
4459 portp->stats.txtotal += len;
4460 stlen = min(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4461 outb(GTXFIFO, (ioaddr + XP_ADDR));
4462 outsb((ioaddr + XP_DATA), tail, stlen);
4465 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4466 tail = portp->tx.buf;
4468 outsb((ioaddr + XP_DATA), tail, len);
4471 portp->tx.tail = tail;
4475 /*****************************************************************************/
4478 * Receive character interrupt handler. Determine if we have good chars
4479 * or bad chars and then process appropriately. Good chars are easy
4480 * just shove the lot into the RX buffer and set all status byte to 0.
4481 * If a bad RX char then process as required. This routine needs to be
4482 * fast! In practice it is possible that we get an interrupt on a port
4483 * that is closed. This can happen on hangups - since they completely
4484 * shutdown a port not in user context. Need to handle this case.
4487 static void stl_sc26198rxisr(struct stlport *portp, unsigned int iack)
4489 struct tty_struct *tty;
4490 unsigned int len, buflen, ioaddr;
4492 pr_debug("stl_sc26198rxisr(portp=%p,iack=%x)\n", portp, iack);
4495 ioaddr = portp->ioaddr;
4496 outb(GIBCR, (ioaddr + XP_ADDR));
4497 len = inb(ioaddr + XP_DATA) + 1;
4499 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
4500 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
4501 len = min(len, sizeof(stl_unwanted));
4502 outb(GRXFIFO, (ioaddr + XP_ADDR));
4503 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4504 portp->stats.rxlost += len;
4505 portp->stats.rxtotal += len;
4507 len = min(len, buflen);
4510 outb(GRXFIFO, (ioaddr + XP_ADDR));
4511 tty_prepare_flip_string(tty, &ptr, len);
4512 insb((ioaddr + XP_DATA), ptr, len);
4513 tty_schedule_flip(tty);
4514 portp->stats.rxtotal += len;
4518 stl_sc26198rxbadchars(portp);
4522 * If we are TX flow controlled and in IXANY mode then we may need
4523 * to unflow control here. We gotta do this because of the automatic
4524 * flow control modes of the sc26198.
4526 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
4527 if ((tty != NULL) &&
4528 (tty->termios != NULL) &&
4529 (tty->termios->c_iflag & IXANY)) {
4530 stl_sc26198txunflow(portp, tty);
4535 /*****************************************************************************/
4538 * Process an RX bad character.
4541 static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch)
4543 struct tty_struct *tty;
4544 unsigned int ioaddr;
4547 ioaddr = portp->ioaddr;
4549 if (status & SR_RXPARITY)
4550 portp->stats.rxparity++;
4551 if (status & SR_RXFRAMING)
4552 portp->stats.rxframing++;
4553 if (status & SR_RXOVERRUN)
4554 portp->stats.rxoverrun++;
4555 if (status & SR_RXBREAK)
4556 portp->stats.rxbreaks++;
4558 if ((tty != NULL) &&
4559 ((portp->rxignoremsk & status) == 0)) {
4560 if (portp->rxmarkmsk & status) {
4561 if (status & SR_RXBREAK) {
4563 if (portp->flags & ASYNC_SAK) {
4565 BRDENABLE(portp->brdnr, portp->pagenr);
4567 } else if (status & SR_RXPARITY)
4568 status = TTY_PARITY;
4569 else if (status & SR_RXFRAMING)
4571 else if(status & SR_RXOVERRUN)
4572 status = TTY_OVERRUN;
4578 tty_insert_flip_char(tty, ch, status);
4579 tty_schedule_flip(tty);
4582 portp->stats.rxtotal++;
4586 /*****************************************************************************/
4589 * Process all characters in the RX FIFO of the UART. Check all char
4590 * status bytes as well, and process as required. We need to check
4591 * all bytes in the FIFO, in case some more enter the FIFO while we
4592 * are here. To get the exact character error type we need to switch
4593 * into CHAR error mode (that is why we need to make sure we empty
4597 static void stl_sc26198rxbadchars(struct stlport *portp)
4599 unsigned char status, mr1;
4603 * To get the precise error type for each character we must switch
4604 * back into CHAR error mode.
4606 mr1 = stl_sc26198getreg(portp, MR1);
4607 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
4609 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
4610 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
4611 ch = stl_sc26198getreg(portp, RXFIFO);
4612 stl_sc26198rxbadch(portp, status, ch);
4616 * To get correct interrupt class we must switch back into BLOCK
4619 stl_sc26198setreg(portp, MR1, mr1);
4622 /*****************************************************************************/
4625 * Other interrupt handler. This includes modem signals, flow
4626 * control actions, etc. Most stuff is left to off-level interrupt
4630 static void stl_sc26198otherisr(struct stlport *portp, unsigned int iack)
4632 unsigned char cir, ipr, xisr;
4634 pr_debug("stl_sc26198otherisr(portp=%p,iack=%x)\n", portp, iack);
4636 cir = stl_sc26198getglobreg(portp, CIR);
4638 switch (cir & CIR_SUBTYPEMASK) {
4640 ipr = stl_sc26198getreg(portp, IPR);
4641 if (ipr & IPR_DCDCHANGE) {
4642 set_bit(ASYI_DCDCHANGE, &portp->istate);
4643 schedule_work(&portp->tqueue);
4644 portp->stats.modem++;
4647 case CIR_SUBXONXOFF:
4648 xisr = stl_sc26198getreg(portp, XISR);
4649 if (xisr & XISR_RXXONGOT) {
4650 set_bit(ASYI_TXFLOWED, &portp->istate);
4651 portp->stats.txxoff++;
4653 if (xisr & XISR_RXXOFFGOT) {
4654 clear_bit(ASYI_TXFLOWED, &portp->istate);
4655 portp->stats.txxon++;
4659 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
4660 stl_sc26198rxbadchars(portp);
4667 static void stl_free_isabrds(void)
4669 struct stlbrd *brdp;
4672 for (i = 0; i < stl_nrbrds; i++) {
4673 if ((brdp = stl_brds[i]) == NULL || (brdp->state & STL_PROBED))
4676 free_irq(brdp->irq, brdp);
4678 stl_cleanup_panels(brdp);
4680 release_region(brdp->ioaddr1, brdp->iosize1);
4681 if (brdp->iosize2 > 0)
4682 release_region(brdp->ioaddr2, brdp->iosize2);
4690 * Loadable module initialization stuff.
4692 static int __init stallion_module_init(void)
4694 struct stlbrd *brdp;
4695 struct stlconf conf;
4699 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
4701 spin_lock_init(&stallion_lock);
4702 spin_lock_init(&brd_lock);
4705 * Find any dynamically supported boards. That is via module load
4708 for (i = stl_nrbrds; i < stl_nargs; i++) {
4709 memset(&conf, 0, sizeof(conf));
4710 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
4712 if ((brdp = stl_allocbrd()) == NULL)
4715 brdp->brdtype = conf.brdtype;
4716 brdp->ioaddr1 = conf.ioaddr1;
4717 brdp->ioaddr2 = conf.ioaddr2;
4718 brdp->irq = conf.irq;
4719 brdp->irqtype = conf.irqtype;
4720 if (stl_brdinit(brdp))
4723 stl_brds[brdp->brdnr] = brdp;
4728 /* this has to be _after_ isa finding because of locking */
4729 retval = pci_register_driver(&stl_pcidriver);
4730 if (retval && stl_nrbrds == 0)
4733 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
4740 * Set up a character driver for per board stuff. This is mainly used
4741 * to do stats ioctls on the ports.
4743 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
4744 printk("STALLION: failed to register serial board device\n");
4746 stallion_class = class_create(THIS_MODULE, "staliomem");
4747 if (IS_ERR(stallion_class)) {
4748 retval = PTR_ERR(stallion_class);
4751 for (i = 0; i < 4; i++)
4752 class_device_create(stallion_class, NULL,
4753 MKDEV(STL_SIOMEMMAJOR, i), NULL,
4756 stl_serial->owner = THIS_MODULE;
4757 stl_serial->driver_name = stl_drvname;
4758 stl_serial->name = "ttyE";
4759 stl_serial->major = STL_SERIALMAJOR;
4760 stl_serial->minor_start = 0;
4761 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
4762 stl_serial->subtype = SERIAL_TYPE_NORMAL;
4763 stl_serial->init_termios = stl_deftermios;
4764 stl_serial->flags = TTY_DRIVER_REAL_RAW;
4765 tty_set_operations(stl_serial, &stl_ops);
4767 retval = tty_register_driver(stl_serial);
4769 printk("STALLION: failed to register serial driver\n");
4775 for (i = 0; i < 4; i++)
4776 class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
4777 class_destroy(stallion_class);
4779 unregister_chrdev(STL_SIOMEMMAJOR, "staliomem");
4780 put_tty_driver(stl_serial);
4782 pci_unregister_driver(&stl_pcidriver);
4788 static void __exit stallion_module_exit(void)
4792 pr_debug("cleanup_module()\n");
4794 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
4798 * Free up all allocated resources used by the ports. This includes
4799 * memory and interrupts. As part of this process we will also do
4800 * a hangup on every open port - to try to flush out any processes
4801 * hanging onto ports.
4803 tty_unregister_driver(stl_serial);
4804 put_tty_driver(stl_serial);
4806 for (i = 0; i < 4; i++)
4807 class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
4808 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
4809 printk("STALLION: failed to un-register serial memory device, "
4811 class_destroy(stallion_class);
4813 pci_unregister_driver(&stl_pcidriver);
4818 module_init(stallion_module_init);
4819 module_exit(stallion_module_exit);
4821 MODULE_AUTHOR("Greg Ungerer");
4822 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
4823 MODULE_LICENSE("GPL");