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/seq_file.h>
36 #include <linux/cd1400.h>
37 #include <linux/sc26198.h>
38 #include <linux/comstats.h>
39 #include <linux/stallion.h>
40 #include <linux/ioport.h>
41 #include <linux/init.h>
42 #include <linux/smp_lock.h>
43 #include <linux/device.h>
44 #include <linux/delay.h>
45 #include <linux/ctype.h>
48 #include <asm/uaccess.h>
50 #include <linux/pci.h>
52 /*****************************************************************************/
55 * Define different board types. Use the standard Stallion "assigned"
56 * board numbers. Boards supported in this driver are abbreviated as
57 * EIO = EasyIO and ECH = EasyConnection 8/32.
63 #define BRD_ECH64PCI 27
64 #define BRD_EASYIOPCI 28
70 unsigned long memaddr;
75 static unsigned int stl_nrbrds;
77 /*****************************************************************************/
80 * Define some important driver characteristics. Device major numbers
81 * allocated as per Linux Device Registry.
83 #ifndef STL_SIOMEMMAJOR
84 #define STL_SIOMEMMAJOR 28
86 #ifndef STL_SERIALMAJOR
87 #define STL_SERIALMAJOR 24
89 #ifndef STL_CALLOUTMAJOR
90 #define STL_CALLOUTMAJOR 25
94 * Set the TX buffer size. Bigger is better, but we don't want
95 * to chew too much memory with buffers!
97 #define STL_TXBUFLOW 512
98 #define STL_TXBUFSIZE 4096
100 /*****************************************************************************/
103 * Define our local driver identity first. Set up stuff to deal with
104 * all the local structures required by a serial tty driver.
106 static char *stl_drvtitle = "Stallion Multiport Serial Driver";
107 static char *stl_drvname = "stallion";
108 static char *stl_drvversion = "5.6.0";
110 static struct tty_driver *stl_serial;
113 * Define a local default termios struct. All ports will be created
114 * with this termios initially. Basically all it defines is a raw port
115 * at 9600, 8 data bits, 1 stop bit.
117 static struct ktermios stl_deftermios = {
118 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
125 * Define global place to put buffer overflow characters.
127 static char stl_unwanted[SC26198_RXFIFOSIZE];
129 /*****************************************************************************/
131 static DEFINE_MUTEX(stl_brdslock);
132 static struct stlbrd *stl_brds[STL_MAXBRDS];
134 static const struct tty_port_operations stl_port_ops;
137 * Per board state flags. Used with the state field of the board struct.
138 * Not really much here!
140 #define BRD_FOUND 0x1
141 #define STL_PROBED 0x2
145 * Define the port structure istate flags. These set of flags are
146 * modified at interrupt time - so setting and reseting them needs
147 * to be atomic. Use the bit clear/setting routines for this.
149 #define ASYI_TXBUSY 1
151 #define ASYI_TXFLOWED 3
154 * Define an array of board names as printable strings. Handy for
155 * referencing boards when printing trace and stuff.
157 static char *stl_brdnames[] = {
189 /*****************************************************************************/
192 * Define some string labels for arguments passed from the module
193 * load line. These allow for easy board definitions, and easy
194 * modification of the io, memory and irq resoucres.
196 static unsigned int stl_nargs;
197 static char *board0[4];
198 static char *board1[4];
199 static char *board2[4];
200 static char *board3[4];
202 static char **stl_brdsp[] = {
210 * Define a set of common board names, and types. This is used to
211 * parse any module arguments.
218 { "easyio", BRD_EASYIO },
219 { "eio", BRD_EASYIO },
220 { "20", BRD_EASYIO },
221 { "ec8/32", BRD_ECH },
222 { "ec8/32-at", BRD_ECH },
223 { "ec8/32-isa", BRD_ECH },
225 { "echat", BRD_ECH },
227 { "ec8/32-mc", BRD_ECHMC },
228 { "ec8/32-mca", BRD_ECHMC },
229 { "echmc", BRD_ECHMC },
230 { "echmca", BRD_ECHMC },
232 { "ec8/32-pc", BRD_ECHPCI },
233 { "ec8/32-pci", BRD_ECHPCI },
234 { "26", BRD_ECHPCI },
235 { "ec8/64-pc", BRD_ECH64PCI },
236 { "ec8/64-pci", BRD_ECH64PCI },
237 { "ech-pci", BRD_ECH64PCI },
238 { "echpci", BRD_ECH64PCI },
239 { "echpc", BRD_ECH64PCI },
240 { "27", BRD_ECH64PCI },
241 { "easyio-pc", BRD_EASYIOPCI },
242 { "easyio-pci", BRD_EASYIOPCI },
243 { "eio-pci", BRD_EASYIOPCI },
244 { "eiopci", BRD_EASYIOPCI },
245 { "28", BRD_EASYIOPCI },
249 * Define the module agruments.
252 module_param_array(board0, charp, &stl_nargs, 0);
253 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
254 module_param_array(board1, charp, &stl_nargs, 0);
255 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
256 module_param_array(board2, charp, &stl_nargs, 0);
257 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
258 module_param_array(board3, charp, &stl_nargs, 0);
259 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
261 /*****************************************************************************/
264 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
265 * to the directly accessible io ports of these boards (not the uarts -
266 * they are in cd1400.h and sc26198.h).
268 #define EIO_8PORTRS 0x04
269 #define EIO_4PORTRS 0x05
270 #define EIO_8PORTDI 0x00
271 #define EIO_8PORTM 0x06
273 #define EIO_IDBITMASK 0x07
275 #define EIO_BRDMASK 0xf0
278 #define ID_BRD16 0x30
280 #define EIO_INTRPEND 0x08
281 #define EIO_INTEDGE 0x00
282 #define EIO_INTLEVEL 0x08
286 #define ECH_IDBITMASK 0xe0
287 #define ECH_BRDENABLE 0x08
288 #define ECH_BRDDISABLE 0x00
289 #define ECH_INTENABLE 0x01
290 #define ECH_INTDISABLE 0x00
291 #define ECH_INTLEVEL 0x02
292 #define ECH_INTEDGE 0x00
293 #define ECH_INTRPEND 0x01
294 #define ECH_BRDRESET 0x01
296 #define ECHMC_INTENABLE 0x01
297 #define ECHMC_BRDRESET 0x02
299 #define ECH_PNLSTATUS 2
300 #define ECH_PNL16PORT 0x20
301 #define ECH_PNLIDMASK 0x07
302 #define ECH_PNLXPID 0x40
303 #define ECH_PNLINTRPEND 0x80
305 #define ECH_ADDR2MASK 0x1e0
308 * Define the vector mapping bits for the programmable interrupt board
309 * hardware. These bits encode the interrupt for the board to use - it
310 * is software selectable (except the EIO-8M).
312 static unsigned char stl_vecmap[] = {
313 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
314 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
318 * Lock ordering is that you may not take stallion_lock holding
322 static spinlock_t brd_lock; /* Guard the board mapping */
323 static spinlock_t stallion_lock; /* Guard the tty driver */
326 * Set up enable and disable macros for the ECH boards. They require
327 * the secondary io address space to be activated and deactivated.
328 * This way all ECH boards can share their secondary io region.
329 * If this is an ECH-PCI board then also need to set the page pointer
330 * to point to the correct page.
332 #define BRDENABLE(brdnr,pagenr) \
333 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
334 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
335 stl_brds[(brdnr)]->ioctrl); \
336 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
337 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
339 #define BRDDISABLE(brdnr) \
340 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
341 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
342 stl_brds[(brdnr)]->ioctrl);
344 #define STL_CD1400MAXBAUD 230400
345 #define STL_SC26198MAXBAUD 460800
347 #define STL_BAUDBASE 115200
348 #define STL_CLOSEDELAY (5 * HZ / 10)
350 /*****************************************************************************/
353 * Define the Stallion PCI vendor and device IDs.
355 #ifndef PCI_VENDOR_ID_STALLION
356 #define PCI_VENDOR_ID_STALLION 0x124d
358 #ifndef PCI_DEVICE_ID_ECHPCI832
359 #define PCI_DEVICE_ID_ECHPCI832 0x0000
361 #ifndef PCI_DEVICE_ID_ECHPCI864
362 #define PCI_DEVICE_ID_ECHPCI864 0x0002
364 #ifndef PCI_DEVICE_ID_EIOPCI
365 #define PCI_DEVICE_ID_EIOPCI 0x0003
369 * Define structure to hold all Stallion PCI boards.
372 static struct pci_device_id stl_pcibrds[] = {
373 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864),
374 .driver_data = BRD_ECH64PCI },
375 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI),
376 .driver_data = BRD_EASYIOPCI },
377 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832),
378 .driver_data = BRD_ECHPCI },
379 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410),
380 .driver_data = BRD_ECHPCI },
383 MODULE_DEVICE_TABLE(pci, stl_pcibrds);
385 /*****************************************************************************/
388 * Define macros to extract a brd/port number from a minor number.
390 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
391 #define MINOR2PORT(min) ((min) & 0x3f)
394 * Define a baud rate table that converts termios baud rate selector
395 * into the actual baud rate value. All baud rate calculations are
396 * based on the actual baud rate required.
398 static unsigned int stl_baudrates[] = {
399 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
400 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
403 /*****************************************************************************/
406 * Declare all those functions in this driver!
409 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
410 static int stl_brdinit(struct stlbrd *brdp);
411 static int stl_getportstats(struct tty_struct *tty, struct stlport *portp, comstats_t __user *cp);
412 static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp);
415 * CD1400 uart specific handling functions.
417 static void stl_cd1400setreg(struct stlport *portp, int regnr, int value);
418 static int stl_cd1400getreg(struct stlport *portp, int regnr);
419 static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value);
420 static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
421 static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
422 static void stl_cd1400setport(struct stlport *portp, struct ktermios *tiosp);
423 static int stl_cd1400getsignals(struct stlport *portp);
424 static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts);
425 static void stl_cd1400ccrwait(struct stlport *portp);
426 static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx);
427 static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx);
428 static void stl_cd1400disableintrs(struct stlport *portp);
429 static void stl_cd1400sendbreak(struct stlport *portp, int len);
430 static void stl_cd1400flowctrl(struct stlport *portp, int state);
431 static void stl_cd1400sendflow(struct stlport *portp, int state);
432 static void stl_cd1400flush(struct stlport *portp);
433 static int stl_cd1400datastate(struct stlport *portp);
434 static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase);
435 static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase);
436 static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr);
437 static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr);
438 static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr);
440 static inline int stl_cd1400breakisr(struct stlport *portp, int ioaddr);
443 * SC26198 uart specific handling functions.
445 static void stl_sc26198setreg(struct stlport *portp, int regnr, int value);
446 static int stl_sc26198getreg(struct stlport *portp, int regnr);
447 static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value);
448 static int stl_sc26198getglobreg(struct stlport *portp, int regnr);
449 static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
450 static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
451 static void stl_sc26198setport(struct stlport *portp, struct ktermios *tiosp);
452 static int stl_sc26198getsignals(struct stlport *portp);
453 static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts);
454 static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx);
455 static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx);
456 static void stl_sc26198disableintrs(struct stlport *portp);
457 static void stl_sc26198sendbreak(struct stlport *portp, int len);
458 static void stl_sc26198flowctrl(struct stlport *portp, int state);
459 static void stl_sc26198sendflow(struct stlport *portp, int state);
460 static void stl_sc26198flush(struct stlport *portp);
461 static int stl_sc26198datastate(struct stlport *portp);
462 static void stl_sc26198wait(struct stlport *portp);
463 static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty);
464 static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase);
465 static void stl_sc26198txisr(struct stlport *port);
466 static void stl_sc26198rxisr(struct stlport *port, unsigned int iack);
467 static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch);
468 static void stl_sc26198rxbadchars(struct stlport *portp);
469 static void stl_sc26198otherisr(struct stlport *port, unsigned int iack);
471 /*****************************************************************************/
474 * Generic UART support structure.
476 typedef struct uart {
477 int (*panelinit)(struct stlbrd *brdp, struct stlpanel *panelp);
478 void (*portinit)(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
479 void (*setport)(struct stlport *portp, struct ktermios *tiosp);
480 int (*getsignals)(struct stlport *portp);
481 void (*setsignals)(struct stlport *portp, int dtr, int rts);
482 void (*enablerxtx)(struct stlport *portp, int rx, int tx);
483 void (*startrxtx)(struct stlport *portp, int rx, int tx);
484 void (*disableintrs)(struct stlport *portp);
485 void (*sendbreak)(struct stlport *portp, int len);
486 void (*flowctrl)(struct stlport *portp, int state);
487 void (*sendflow)(struct stlport *portp, int state);
488 void (*flush)(struct stlport *portp);
489 int (*datastate)(struct stlport *portp);
490 void (*intr)(struct stlpanel *panelp, unsigned int iobase);
494 * Define some macros to make calling these functions nice and clean.
496 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
497 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
498 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
499 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
500 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
501 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
502 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
503 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
504 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
505 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
506 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
507 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
508 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
510 /*****************************************************************************/
513 * CD1400 UART specific data initialization.
515 static uart_t stl_cd1400uart = {
519 stl_cd1400getsignals,
520 stl_cd1400setsignals,
521 stl_cd1400enablerxtx,
523 stl_cd1400disableintrs,
533 * Define the offsets within the register bank of a cd1400 based panel.
534 * These io address offsets are common to the EasyIO board as well.
542 #define EREG_BANKSIZE 8
544 #define CD1400_CLK 25000000
545 #define CD1400_CLK8M 20000000
548 * Define the cd1400 baud rate clocks. These are used when calculating
549 * what clock and divisor to use for the required baud rate. Also
550 * define the maximum baud rate allowed, and the default base baud.
552 static int stl_cd1400clkdivs[] = {
553 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
556 /*****************************************************************************/
559 * SC26198 UART specific data initization.
561 static uart_t stl_sc26198uart = {
562 stl_sc26198panelinit,
565 stl_sc26198getsignals,
566 stl_sc26198setsignals,
567 stl_sc26198enablerxtx,
568 stl_sc26198startrxtx,
569 stl_sc26198disableintrs,
570 stl_sc26198sendbreak,
574 stl_sc26198datastate,
579 * Define the offsets within the register bank of a sc26198 based panel.
587 #define XP_BANKSIZE 4
590 * Define the sc26198 baud rate table. Offsets within the table
591 * represent the actual baud rate selector of sc26198 registers.
593 static unsigned int sc26198_baudtable[] = {
594 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
595 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
596 230400, 460800, 921600
599 #define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
601 /*****************************************************************************/
604 * Define the driver info for a user level control device. Used mainly
605 * to get at port stats - only not using the port device itself.
607 static const struct file_operations stl_fsiomem = {
608 .owner = THIS_MODULE,
609 .ioctl = stl_memioctl,
612 static struct class *stallion_class;
614 static void stl_cd_change(struct stlport *portp)
616 unsigned int oldsigs = portp->sigs;
617 struct tty_struct *tty = tty_port_tty_get(&portp->port);
622 portp->sigs = stl_getsignals(portp);
624 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
625 wake_up_interruptible(&portp->port.open_wait);
627 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0))
628 if (portp->port.flags & ASYNC_CHECK_CD)
634 * Check for any arguments passed in on the module load command line.
637 /*****************************************************************************/
640 * Parse the supplied argument string, into the board conf struct.
643 static int __init stl_parsebrd(struct stlconf *confp, char **argp)
648 pr_debug("stl_parsebrd(confp=%p,argp=%p)\n", confp, argp);
650 if ((argp[0] == NULL) || (*argp[0] == 0))
653 for (sp = argp[0], i = 0; (*sp != 0) && (i < 25); sp++, i++)
656 for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++)
657 if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
660 if (i == ARRAY_SIZE(stl_brdstr)) {
661 printk("STALLION: unknown board name, %s?\n", argp[0]);
665 confp->brdtype = stl_brdstr[i].type;
668 if ((argp[i] != NULL) && (*argp[i] != 0))
669 confp->ioaddr1 = simple_strtoul(argp[i], NULL, 0);
671 if (confp->brdtype == BRD_ECH) {
672 if ((argp[i] != NULL) && (*argp[i] != 0))
673 confp->ioaddr2 = simple_strtoul(argp[i], NULL, 0);
676 if ((argp[i] != NULL) && (*argp[i] != 0))
677 confp->irq = simple_strtoul(argp[i], NULL, 0);
681 /*****************************************************************************/
684 * Allocate a new board structure. Fill out the basic info in it.
687 static struct stlbrd *stl_allocbrd(void)
691 brdp = kzalloc(sizeof(struct stlbrd), GFP_KERNEL);
693 printk("STALLION: failed to allocate memory (size=%Zd)\n",
694 sizeof(struct stlbrd));
698 brdp->magic = STL_BOARDMAGIC;
702 /*****************************************************************************/
704 static int stl_open(struct tty_struct *tty, struct file *filp)
706 struct stlport *portp;
708 struct tty_port *port;
709 unsigned int minordev, brdnr, panelnr;
712 pr_debug("stl_open(tty=%p,filp=%p): device=%s\n", tty, filp, tty->name);
714 minordev = tty->index;
715 brdnr = MINOR2BRD(minordev);
716 if (brdnr >= stl_nrbrds)
718 brdp = stl_brds[brdnr];
722 minordev = MINOR2PORT(minordev);
723 for (portnr = -1, panelnr = 0; panelnr < STL_MAXPANELS; panelnr++) {
724 if (brdp->panels[panelnr] == NULL)
726 if (minordev < brdp->panels[panelnr]->nrports) {
730 minordev -= brdp->panels[panelnr]->nrports;
735 portp = brdp->panels[panelnr]->ports[portnr];
741 * On the first open of the device setup the port hardware, and
742 * initialize the per port data structure.
744 tty_port_tty_set(port, tty);
745 tty->driver_data = portp;
748 if ((port->flags & ASYNC_INITIALIZED) == 0) {
749 if (!portp->tx.buf) {
750 portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
753 portp->tx.head = portp->tx.buf;
754 portp->tx.tail = portp->tx.buf;
756 stl_setport(portp, tty->termios);
757 portp->sigs = stl_getsignals(portp);
758 stl_setsignals(portp, 1, 1);
759 stl_enablerxtx(portp, 1, 1);
760 stl_startrxtx(portp, 1, 0);
761 clear_bit(TTY_IO_ERROR, &tty->flags);
762 port->flags |= ASYNC_INITIALIZED;
764 return tty_port_block_til_ready(port, tty, filp);
767 /*****************************************************************************/
769 static int stl_carrier_raised(struct tty_port *port)
771 struct stlport *portp = container_of(port, struct stlport, port);
772 return (portp->sigs & TIOCM_CD) ? 1 : 0;
775 static void stl_dtr_rts(struct tty_port *port, int on)
777 struct stlport *portp = container_of(port, struct stlport, port);
778 /* Takes brd_lock internally */
779 stl_setsignals(portp, on, on);
782 /*****************************************************************************/
784 static void stl_flushbuffer(struct tty_struct *tty)
786 struct stlport *portp;
788 pr_debug("stl_flushbuffer(tty=%p)\n", tty);
790 portp = tty->driver_data;
798 /*****************************************************************************/
800 static void stl_waituntilsent(struct tty_struct *tty, int timeout)
802 struct stlport *portp;
805 pr_debug("stl_waituntilsent(tty=%p,timeout=%d)\n", tty, timeout);
807 portp = tty->driver_data;
813 tend = jiffies + timeout;
816 while (stl_datastate(portp)) {
817 if (signal_pending(current))
819 msleep_interruptible(20);
820 if (time_after_eq(jiffies, tend))
826 /*****************************************************************************/
828 static void stl_close(struct tty_struct *tty, struct file *filp)
830 struct stlport *portp;
831 struct tty_port *port;
834 pr_debug("stl_close(tty=%p,filp=%p)\n", tty, filp);
836 portp = tty->driver_data;
837 BUG_ON(portp == NULL);
841 if (tty_port_close_start(port, tty, filp) == 0)
844 * May want to wait for any data to drain before closing. The BUSY
845 * flag keeps track of whether we are still sending or not - it is
846 * very accurate for the cd1400, not quite so for the sc26198.
847 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
849 stl_waituntilsent(tty, (HZ / 2));
851 spin_lock_irqsave(&port->lock, flags);
852 portp->port.flags &= ~ASYNC_INITIALIZED;
853 spin_unlock_irqrestore(&port->lock, flags);
855 stl_disableintrs(portp);
856 if (tty->termios->c_cflag & HUPCL)
857 stl_setsignals(portp, 0, 0);
858 stl_enablerxtx(portp, 0, 0);
859 stl_flushbuffer(tty);
861 if (portp->tx.buf != NULL) {
862 kfree(portp->tx.buf);
863 portp->tx.buf = NULL;
864 portp->tx.head = NULL;
865 portp->tx.tail = NULL;
868 tty_port_close_end(port, tty);
869 tty_port_tty_set(port, NULL);
872 /*****************************************************************************/
875 * Write routine. Take data and stuff it in to the TX ring queue.
876 * If transmit interrupts are not running then start them.
879 static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
881 struct stlport *portp;
882 unsigned int len, stlen;
883 unsigned char *chbuf;
886 pr_debug("stl_write(tty=%p,buf=%p,count=%d)\n", tty, buf, count);
888 portp = tty->driver_data;
891 if (portp->tx.buf == NULL)
895 * If copying direct from user space we must cater for page faults,
896 * causing us to "sleep" here for a while. To handle this copy in all
897 * the data we need now, into a local buffer. Then when we got it all
898 * copy it into the TX buffer.
900 chbuf = (unsigned char *) buf;
902 head = portp->tx.head;
903 tail = portp->tx.tail;
905 len = STL_TXBUFSIZE - (head - tail) - 1;
906 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
908 len = tail - head - 1;
912 len = min(len, (unsigned int)count);
915 stlen = min(len, stlen);
916 memcpy(head, chbuf, stlen);
921 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
922 head = portp->tx.buf;
926 portp->tx.head = head;
928 clear_bit(ASYI_TXLOW, &portp->istate);
929 stl_startrxtx(portp, -1, 1);
934 /*****************************************************************************/
936 static int stl_putchar(struct tty_struct *tty, unsigned char ch)
938 struct stlport *portp;
942 pr_debug("stl_putchar(tty=%p,ch=%x)\n", tty, ch);
944 portp = tty->driver_data;
947 if (portp->tx.buf == NULL)
950 head = portp->tx.head;
951 tail = portp->tx.tail;
953 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
958 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
959 head = portp->tx.buf;
961 portp->tx.head = head;
965 /*****************************************************************************/
968 * If there are any characters in the buffer then make sure that TX
969 * interrupts are on and get'em out. Normally used after the putchar
970 * routine has been called.
973 static void stl_flushchars(struct tty_struct *tty)
975 struct stlport *portp;
977 pr_debug("stl_flushchars(tty=%p)\n", tty);
979 portp = tty->driver_data;
982 if (portp->tx.buf == NULL)
985 stl_startrxtx(portp, -1, 1);
988 /*****************************************************************************/
990 static int stl_writeroom(struct tty_struct *tty)
992 struct stlport *portp;
995 pr_debug("stl_writeroom(tty=%p)\n", tty);
997 portp = tty->driver_data;
1000 if (portp->tx.buf == NULL)
1003 head = portp->tx.head;
1004 tail = portp->tx.tail;
1005 return (head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1);
1008 /*****************************************************************************/
1011 * Return number of chars in the TX buffer. Normally we would just
1012 * calculate the number of chars in the buffer and return that, but if
1013 * the buffer is empty and TX interrupts are still on then we return
1014 * that the buffer still has 1 char in it. This way whoever called us
1015 * will not think that ALL chars have drained - since the UART still
1016 * must have some chars in it (we are busy after all).
1019 static int stl_charsinbuffer(struct tty_struct *tty)
1021 struct stlport *portp;
1025 pr_debug("stl_charsinbuffer(tty=%p)\n", tty);
1027 portp = tty->driver_data;
1030 if (portp->tx.buf == NULL)
1033 head = portp->tx.head;
1034 tail = portp->tx.tail;
1035 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1036 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1041 /*****************************************************************************/
1044 * Generate the serial struct info.
1047 static int stl_getserial(struct stlport *portp, struct serial_struct __user *sp)
1049 struct serial_struct sio;
1050 struct stlbrd *brdp;
1052 pr_debug("stl_getserial(portp=%p,sp=%p)\n", portp, sp);
1054 memset(&sio, 0, sizeof(struct serial_struct));
1055 sio.line = portp->portnr;
1056 sio.port = portp->ioaddr;
1057 sio.flags = portp->port.flags;
1058 sio.baud_base = portp->baud_base;
1059 sio.close_delay = portp->close_delay;
1060 sio.closing_wait = portp->closing_wait;
1061 sio.custom_divisor = portp->custom_divisor;
1063 if (portp->uartp == &stl_cd1400uart) {
1064 sio.type = PORT_CIRRUS;
1065 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1067 sio.type = PORT_UNKNOWN;
1068 sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1071 brdp = stl_brds[portp->brdnr];
1073 sio.irq = brdp->irq;
1075 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
1078 /*****************************************************************************/
1081 * Set port according to the serial struct info.
1082 * At this point we do not do any auto-configure stuff, so we will
1083 * just quietly ignore any requests to change irq, etc.
1086 static int stl_setserial(struct tty_struct *tty, struct serial_struct __user *sp)
1088 struct stlport * portp = tty->driver_data;
1089 struct serial_struct sio;
1091 pr_debug("stl_setserial(portp=%p,sp=%p)\n", portp, sp);
1093 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1095 if (!capable(CAP_SYS_ADMIN)) {
1096 if ((sio.baud_base != portp->baud_base) ||
1097 (sio.close_delay != portp->close_delay) ||
1098 ((sio.flags & ~ASYNC_USR_MASK) !=
1099 (portp->port.flags & ~ASYNC_USR_MASK)))
1103 portp->port.flags = (portp->port.flags & ~ASYNC_USR_MASK) |
1104 (sio.flags & ASYNC_USR_MASK);
1105 portp->baud_base = sio.baud_base;
1106 portp->close_delay = sio.close_delay;
1107 portp->closing_wait = sio.closing_wait;
1108 portp->custom_divisor = sio.custom_divisor;
1109 stl_setport(portp, tty->termios);
1113 /*****************************************************************************/
1115 static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1117 struct stlport *portp;
1119 portp = tty->driver_data;
1122 if (tty->flags & (1 << TTY_IO_ERROR))
1125 return stl_getsignals(portp);
1128 static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1129 unsigned int set, unsigned int clear)
1131 struct stlport *portp;
1132 int rts = -1, dtr = -1;
1134 portp = tty->driver_data;
1137 if (tty->flags & (1 << TTY_IO_ERROR))
1140 if (set & TIOCM_RTS)
1142 if (set & TIOCM_DTR)
1144 if (clear & TIOCM_RTS)
1146 if (clear & TIOCM_DTR)
1149 stl_setsignals(portp, dtr, rts);
1153 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1155 struct stlport *portp;
1157 void __user *argp = (void __user *)arg;
1159 pr_debug("stl_ioctl(tty=%p,file=%p,cmd=%x,arg=%lx)\n", tty, file, cmd,
1162 portp = tty->driver_data;
1166 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1167 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS))
1168 if (tty->flags & (1 << TTY_IO_ERROR))
1177 rc = stl_getserial(portp, argp);
1180 rc = stl_setserial(tty, argp);
1182 case COM_GETPORTSTATS:
1183 rc = stl_getportstats(tty, portp, argp);
1185 case COM_CLRPORTSTATS:
1186 rc = stl_clrportstats(portp, argp);
1192 case TIOCSERGSTRUCT:
1193 case TIOCSERGETMULTI:
1194 case TIOCSERSETMULTI:
1203 /*****************************************************************************/
1206 * Start the transmitter again. Just turn TX interrupts back on.
1209 static void stl_start(struct tty_struct *tty)
1211 struct stlport *portp;
1213 pr_debug("stl_start(tty=%p)\n", tty);
1215 portp = tty->driver_data;
1218 stl_startrxtx(portp, -1, 1);
1221 /*****************************************************************************/
1223 static void stl_settermios(struct tty_struct *tty, struct ktermios *old)
1225 struct stlport *portp;
1226 struct ktermios *tiosp;
1228 pr_debug("stl_settermios(tty=%p,old=%p)\n", tty, old);
1230 portp = tty->driver_data;
1234 tiosp = tty->termios;
1235 if ((tiosp->c_cflag == old->c_cflag) &&
1236 (tiosp->c_iflag == old->c_iflag))
1239 stl_setport(portp, tiosp);
1240 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1242 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1243 tty->hw_stopped = 0;
1246 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1247 wake_up_interruptible(&portp->port.open_wait);
1250 /*****************************************************************************/
1253 * Attempt to flow control who ever is sending us data. Based on termios
1254 * settings use software or/and hardware flow control.
1257 static void stl_throttle(struct tty_struct *tty)
1259 struct stlport *portp;
1261 pr_debug("stl_throttle(tty=%p)\n", tty);
1263 portp = tty->driver_data;
1266 stl_flowctrl(portp, 0);
1269 /*****************************************************************************/
1272 * Unflow control the device sending us data...
1275 static void stl_unthrottle(struct tty_struct *tty)
1277 struct stlport *portp;
1279 pr_debug("stl_unthrottle(tty=%p)\n", tty);
1281 portp = tty->driver_data;
1284 stl_flowctrl(portp, 1);
1287 /*****************************************************************************/
1290 * Stop the transmitter. Basically to do this we will just turn TX
1294 static void stl_stop(struct tty_struct *tty)
1296 struct stlport *portp;
1298 pr_debug("stl_stop(tty=%p)\n", tty);
1300 portp = tty->driver_data;
1303 stl_startrxtx(portp, -1, 0);
1306 /*****************************************************************************/
1309 * Hangup this port. This is pretty much like closing the port, only
1310 * a little more brutal. No waiting for data to drain. Shutdown the
1311 * port and maybe drop signals.
1314 static void stl_hangup(struct tty_struct *tty)
1316 struct stlport *portp;
1317 struct tty_port *port;
1318 unsigned long flags;
1320 pr_debug("stl_hangup(tty=%p)\n", tty);
1322 portp = tty->driver_data;
1325 port = &portp->port;
1327 spin_lock_irqsave(&port->lock, flags);
1328 port->flags &= ~ASYNC_INITIALIZED;
1329 spin_unlock_irqrestore(&port->lock, flags);
1331 stl_disableintrs(portp);
1332 if (tty->termios->c_cflag & HUPCL)
1333 stl_setsignals(portp, 0, 0);
1334 stl_enablerxtx(portp, 0, 0);
1335 stl_flushbuffer(tty);
1337 set_bit(TTY_IO_ERROR, &tty->flags);
1338 if (portp->tx.buf != NULL) {
1339 kfree(portp->tx.buf);
1340 portp->tx.buf = NULL;
1341 portp->tx.head = NULL;
1342 portp->tx.tail = NULL;
1344 tty_port_hangup(port);
1347 /*****************************************************************************/
1349 static int stl_breakctl(struct tty_struct *tty, int state)
1351 struct stlport *portp;
1353 pr_debug("stl_breakctl(tty=%p,state=%d)\n", tty, state);
1355 portp = tty->driver_data;
1359 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1363 /*****************************************************************************/
1365 static void stl_sendxchar(struct tty_struct *tty, char ch)
1367 struct stlport *portp;
1369 pr_debug("stl_sendxchar(tty=%p,ch=%x)\n", tty, ch);
1371 portp = tty->driver_data;
1375 if (ch == STOP_CHAR(tty))
1376 stl_sendflow(portp, 0);
1377 else if (ch == START_CHAR(tty))
1378 stl_sendflow(portp, 1);
1380 stl_putchar(tty, ch);
1383 static void stl_portinfo(struct seq_file *m, struct stlport *portp, int portnr)
1388 seq_printf(m, "%d: uart:%s tx:%d rx:%d",
1389 portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
1390 (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
1392 if (portp->stats.rxframing)
1393 seq_printf(m, " fe:%d", (int) portp->stats.rxframing);
1394 if (portp->stats.rxparity)
1395 seq_printf(m, " pe:%d", (int) portp->stats.rxparity);
1396 if (portp->stats.rxbreaks)
1397 seq_printf(m, " brk:%d", (int) portp->stats.rxbreaks);
1398 if (portp->stats.rxoverrun)
1399 seq_printf(m, " oe:%d", (int) portp->stats.rxoverrun);
1401 sigs = stl_getsignals(portp);
1403 if (sigs & TIOCM_RTS) {
1404 seq_printf(m, "%c%s", sep, "RTS");
1407 if (sigs & TIOCM_CTS) {
1408 seq_printf(m, "%c%s", sep, "CTS");
1411 if (sigs & TIOCM_DTR) {
1412 seq_printf(m, "%c%s", sep, "DTR");
1415 if (sigs & TIOCM_CD) {
1416 seq_printf(m, "%c%s", sep, "DCD");
1419 if (sigs & TIOCM_DSR) {
1420 seq_printf(m, "%c%s", sep, "DSR");
1426 /*****************************************************************************/
1429 * Port info, read from the /proc file system.
1432 static int stl_proc_show(struct seq_file *m, void *v)
1434 struct stlbrd *brdp;
1435 struct stlpanel *panelp;
1436 struct stlport *portp;
1437 unsigned int brdnr, panelnr, portnr;
1442 seq_printf(m, "%s: version %s\n", stl_drvtitle, stl_drvversion);
1445 * We scan through for each board, panel and port. The offset is
1446 * calculated on the fly, and irrelevant ports are skipped.
1448 for (brdnr = 0; brdnr < stl_nrbrds; brdnr++) {
1449 brdp = stl_brds[brdnr];
1452 if (brdp->state == 0)
1455 totalport = brdnr * STL_MAXPORTS;
1456 for (panelnr = 0; panelnr < brdp->nrpanels; panelnr++) {
1457 panelp = brdp->panels[panelnr];
1461 for (portnr = 0; portnr < panelp->nrports; portnr++,
1463 portp = panelp->ports[portnr];
1466 stl_portinfo(m, portp, totalport);
1473 static int stl_proc_open(struct inode *inode, struct file *file)
1475 return single_open(file, stl_proc_show, NULL);
1478 static const struct file_operations stl_proc_fops = {
1479 .owner = THIS_MODULE,
1480 .open = stl_proc_open,
1482 .llseek = seq_lseek,
1483 .release = single_release,
1486 /*****************************************************************************/
1489 * All board interrupts are vectored through here first. This code then
1490 * calls off to the approrpriate board interrupt handlers.
1493 static irqreturn_t stl_intr(int irq, void *dev_id)
1495 struct stlbrd *brdp = dev_id;
1497 pr_debug("stl_intr(brdp=%p,irq=%d)\n", brdp, brdp->irq);
1499 return IRQ_RETVAL((* brdp->isr)(brdp));
1502 /*****************************************************************************/
1505 * Interrupt service routine for EasyIO board types.
1508 static int stl_eiointr(struct stlbrd *brdp)
1510 struct stlpanel *panelp;
1511 unsigned int iobase;
1514 spin_lock(&brd_lock);
1515 panelp = brdp->panels[0];
1516 iobase = panelp->iobase;
1517 while (inb(brdp->iostatus) & EIO_INTRPEND) {
1519 (* panelp->isr)(panelp, iobase);
1521 spin_unlock(&brd_lock);
1525 /*****************************************************************************/
1528 * Interrupt service routine for ECH-AT board types.
1531 static int stl_echatintr(struct stlbrd *brdp)
1533 struct stlpanel *panelp;
1534 unsigned int ioaddr, bnknr;
1537 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
1539 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1541 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
1542 ioaddr = brdp->bnkstataddr[bnknr];
1543 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1544 panelp = brdp->bnk2panel[bnknr];
1545 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1550 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
1555 /*****************************************************************************/
1558 * Interrupt service routine for ECH-MCA board types.
1561 static int stl_echmcaintr(struct stlbrd *brdp)
1563 struct stlpanel *panelp;
1564 unsigned int ioaddr, bnknr;
1567 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1569 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
1570 ioaddr = brdp->bnkstataddr[bnknr];
1571 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1572 panelp = brdp->bnk2panel[bnknr];
1573 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1580 /*****************************************************************************/
1583 * Interrupt service routine for ECH-PCI board types.
1586 static int stl_echpciintr(struct stlbrd *brdp)
1588 struct stlpanel *panelp;
1589 unsigned int ioaddr, bnknr, recheck;
1594 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
1595 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
1596 ioaddr = brdp->bnkstataddr[bnknr];
1597 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1598 panelp = brdp->bnk2panel[bnknr];
1599 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1610 /*****************************************************************************/
1613 * Interrupt service routine for ECH-8/64-PCI board types.
1616 static int stl_echpci64intr(struct stlbrd *brdp)
1618 struct stlpanel *panelp;
1619 unsigned int ioaddr, bnknr;
1622 while (inb(brdp->ioctrl) & 0x1) {
1624 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
1625 ioaddr = brdp->bnkstataddr[bnknr];
1626 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1627 panelp = brdp->bnk2panel[bnknr];
1628 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1636 /*****************************************************************************/
1639 * Initialize all the ports on a panel.
1642 static int __devinit stl_initports(struct stlbrd *brdp, struct stlpanel *panelp)
1644 struct stlport *portp;
1648 pr_debug("stl_initports(brdp=%p,panelp=%p)\n", brdp, panelp);
1650 chipmask = stl_panelinit(brdp, panelp);
1653 * All UART's are initialized (if found!). Now go through and setup
1654 * each ports data structures.
1656 for (i = 0; i < panelp->nrports; i++) {
1657 portp = kzalloc(sizeof(struct stlport), GFP_KERNEL);
1659 printk("STALLION: failed to allocate memory "
1660 "(size=%Zd)\n", sizeof(struct stlport));
1663 tty_port_init(&portp->port);
1664 portp->port.ops = &stl_port_ops;
1665 portp->magic = STL_PORTMAGIC;
1667 portp->brdnr = panelp->brdnr;
1668 portp->panelnr = panelp->panelnr;
1669 portp->uartp = panelp->uartp;
1670 portp->clk = brdp->clk;
1671 portp->baud_base = STL_BAUDBASE;
1672 portp->close_delay = STL_CLOSEDELAY;
1673 portp->closing_wait = 30 * HZ;
1674 init_waitqueue_head(&portp->port.open_wait);
1675 init_waitqueue_head(&portp->port.close_wait);
1676 portp->stats.brd = portp->brdnr;
1677 portp->stats.panel = portp->panelnr;
1678 portp->stats.port = portp->portnr;
1679 panelp->ports[i] = portp;
1680 stl_portinit(brdp, panelp, portp);
1686 static void stl_cleanup_panels(struct stlbrd *brdp)
1688 struct stlpanel *panelp;
1689 struct stlport *portp;
1691 struct tty_struct *tty;
1693 for (j = 0; j < STL_MAXPANELS; j++) {
1694 panelp = brdp->panels[j];
1697 for (k = 0; k < STL_PORTSPERPANEL; k++) {
1698 portp = panelp->ports[k];
1701 tty = tty_port_tty_get(&portp->port);
1706 kfree(portp->tx.buf);
1713 /*****************************************************************************/
1716 * Try to find and initialize an EasyIO board.
1719 static int __devinit stl_initeio(struct stlbrd *brdp)
1721 struct stlpanel *panelp;
1722 unsigned int status;
1726 pr_debug("stl_initeio(brdp=%p)\n", brdp);
1728 brdp->ioctrl = brdp->ioaddr1 + 1;
1729 brdp->iostatus = brdp->ioaddr1 + 2;
1731 status = inb(brdp->iostatus);
1732 if ((status & EIO_IDBITMASK) == EIO_MK3)
1736 * Handle board specific stuff now. The real difference is PCI
1739 if (brdp->brdtype == BRD_EASYIOPCI) {
1740 brdp->iosize1 = 0x80;
1741 brdp->iosize2 = 0x80;
1742 name = "serial(EIO-PCI)";
1743 outb(0x41, (brdp->ioaddr2 + 0x4c));
1746 name = "serial(EIO)";
1747 if ((brdp->irq < 0) || (brdp->irq > 15) ||
1748 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
1749 printk("STALLION: invalid irq=%d for brd=%d\n",
1750 brdp->irq, brdp->brdnr);
1754 outb((stl_vecmap[brdp->irq] | EIO_0WS |
1755 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
1760 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
1761 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
1762 "%x conflicts with another device\n", brdp->brdnr,
1767 if (brdp->iosize2 > 0)
1768 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
1769 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
1770 "address %x conflicts with another device\n",
1771 brdp->brdnr, brdp->ioaddr2);
1772 printk(KERN_WARNING "STALLION: Warning, also "
1773 "releasing board %d I/O address %x \n",
1774 brdp->brdnr, brdp->ioaddr1);
1779 * Everything looks OK, so let's go ahead and probe for the hardware.
1781 brdp->clk = CD1400_CLK;
1782 brdp->isr = stl_eiointr;
1785 switch (status & EIO_IDBITMASK) {
1787 brdp->clk = CD1400_CLK8M;
1797 switch (status & EIO_BRDMASK) {
1816 * We have verified that the board is actually present, so now we
1817 * can complete the setup.
1820 panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
1822 printk(KERN_WARNING "STALLION: failed to allocate memory "
1823 "(size=%Zd)\n", sizeof(struct stlpanel));
1828 panelp->magic = STL_PANELMAGIC;
1829 panelp->brdnr = brdp->brdnr;
1830 panelp->panelnr = 0;
1831 panelp->nrports = brdp->nrports;
1832 panelp->iobase = brdp->ioaddr1;
1833 panelp->hwid = status;
1834 if ((status & EIO_IDBITMASK) == EIO_MK3) {
1835 panelp->uartp = &stl_sc26198uart;
1836 panelp->isr = stl_sc26198intr;
1838 panelp->uartp = &stl_cd1400uart;
1839 panelp->isr = stl_cd1400eiointr;
1842 brdp->panels[0] = panelp;
1844 brdp->state |= BRD_FOUND;
1845 brdp->hwid = status;
1846 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
1847 printk("STALLION: failed to register interrupt "
1848 "routine for %s irq=%d\n", name, brdp->irq);
1855 stl_cleanup_panels(brdp);
1857 if (brdp->iosize2 > 0)
1858 release_region(brdp->ioaddr2, brdp->iosize2);
1860 release_region(brdp->ioaddr1, brdp->iosize1);
1865 /*****************************************************************************/
1868 * Try to find an ECH board and initialize it. This code is capable of
1869 * dealing with all types of ECH board.
1872 static int __devinit stl_initech(struct stlbrd *brdp)
1874 struct stlpanel *panelp;
1875 unsigned int status, nxtid, ioaddr, conflict, panelnr, banknr, i;
1879 pr_debug("stl_initech(brdp=%p)\n", brdp);
1885 * Set up the initial board register contents for boards. This varies a
1886 * bit between the different board types. So we need to handle each
1887 * separately. Also do a check that the supplied IRQ is good.
1889 switch (brdp->brdtype) {
1892 brdp->isr = stl_echatintr;
1893 brdp->ioctrl = brdp->ioaddr1 + 1;
1894 brdp->iostatus = brdp->ioaddr1 + 1;
1895 status = inb(brdp->iostatus);
1896 if ((status & ECH_IDBITMASK) != ECH_ID) {
1900 if ((brdp->irq < 0) || (brdp->irq > 15) ||
1901 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
1902 printk("STALLION: invalid irq=%d for brd=%d\n",
1903 brdp->irq, brdp->brdnr);
1907 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
1908 status |= (stl_vecmap[brdp->irq] << 1);
1909 outb((status | ECH_BRDRESET), brdp->ioaddr1);
1910 brdp->ioctrlval = ECH_INTENABLE |
1911 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
1912 for (i = 0; i < 10; i++)
1913 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
1916 name = "serial(EC8/32)";
1917 outb(status, brdp->ioaddr1);
1921 brdp->isr = stl_echmcaintr;
1922 brdp->ioctrl = brdp->ioaddr1 + 0x20;
1923 brdp->iostatus = brdp->ioctrl;
1924 status = inb(brdp->iostatus);
1925 if ((status & ECH_IDBITMASK) != ECH_ID) {
1929 if ((brdp->irq < 0) || (brdp->irq > 15) ||
1930 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
1931 printk("STALLION: invalid irq=%d for brd=%d\n",
1932 brdp->irq, brdp->brdnr);
1936 outb(ECHMC_BRDRESET, brdp->ioctrl);
1937 outb(ECHMC_INTENABLE, brdp->ioctrl);
1939 name = "serial(EC8/32-MC)";
1943 brdp->isr = stl_echpciintr;
1944 brdp->ioctrl = brdp->ioaddr1 + 2;
1947 name = "serial(EC8/32-PCI)";
1951 brdp->isr = stl_echpci64intr;
1952 brdp->ioctrl = brdp->ioaddr2 + 0x40;
1953 outb(0x43, (brdp->ioaddr1 + 0x4c));
1954 brdp->iosize1 = 0x80;
1955 brdp->iosize2 = 0x80;
1956 name = "serial(EC8/64-PCI)";
1960 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
1966 * Check boards for possible IO address conflicts and return fail status
1967 * if an IO conflict found.
1970 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
1971 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
1972 "%x conflicts with another device\n", brdp->brdnr,
1977 if (brdp->iosize2 > 0)
1978 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
1979 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
1980 "address %x conflicts with another device\n",
1981 brdp->brdnr, brdp->ioaddr2);
1982 printk(KERN_WARNING "STALLION: Warning, also "
1983 "releasing board %d I/O address %x \n",
1984 brdp->brdnr, brdp->ioaddr1);
1989 * Scan through the secondary io address space looking for panels.
1990 * As we find'em allocate and initialize panel structures for each.
1992 brdp->clk = CD1400_CLK;
1993 brdp->hwid = status;
1995 ioaddr = brdp->ioaddr2;
2000 for (i = 0; i < STL_MAXPANELS; i++) {
2001 if (brdp->brdtype == BRD_ECHPCI) {
2002 outb(nxtid, brdp->ioctrl);
2003 ioaddr = brdp->ioaddr2;
2005 status = inb(ioaddr + ECH_PNLSTATUS);
2006 if ((status & ECH_PNLIDMASK) != nxtid)
2008 panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
2010 printk("STALLION: failed to allocate memory "
2011 "(size=%Zd)\n", sizeof(struct stlpanel));
2015 panelp->magic = STL_PANELMAGIC;
2016 panelp->brdnr = brdp->brdnr;
2017 panelp->panelnr = panelnr;
2018 panelp->iobase = ioaddr;
2019 panelp->pagenr = nxtid;
2020 panelp->hwid = status;
2021 brdp->bnk2panel[banknr] = panelp;
2022 brdp->bnkpageaddr[banknr] = nxtid;
2023 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2025 if (status & ECH_PNLXPID) {
2026 panelp->uartp = &stl_sc26198uart;
2027 panelp->isr = stl_sc26198intr;
2028 if (status & ECH_PNL16PORT) {
2029 panelp->nrports = 16;
2030 brdp->bnk2panel[banknr] = panelp;
2031 brdp->bnkpageaddr[banknr] = nxtid;
2032 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2035 panelp->nrports = 8;
2037 panelp->uartp = &stl_cd1400uart;
2038 panelp->isr = stl_cd1400echintr;
2039 if (status & ECH_PNL16PORT) {
2040 panelp->nrports = 16;
2041 panelp->ackmask = 0x80;
2042 if (brdp->brdtype != BRD_ECHPCI)
2043 ioaddr += EREG_BANKSIZE;
2044 brdp->bnk2panel[banknr] = panelp;
2045 brdp->bnkpageaddr[banknr] = ++nxtid;
2046 brdp->bnkstataddr[banknr++] = ioaddr +
2049 panelp->nrports = 8;
2050 panelp->ackmask = 0xc0;
2055 ioaddr += EREG_BANKSIZE;
2056 brdp->nrports += panelp->nrports;
2057 brdp->panels[panelnr++] = panelp;
2058 if ((brdp->brdtype != BRD_ECHPCI) &&
2059 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2))) {
2065 brdp->nrpanels = panelnr;
2066 brdp->nrbnks = banknr;
2067 if (brdp->brdtype == BRD_ECH)
2068 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2070 brdp->state |= BRD_FOUND;
2071 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
2072 printk("STALLION: failed to register interrupt "
2073 "routine for %s irq=%d\n", name, brdp->irq);
2080 stl_cleanup_panels(brdp);
2081 if (brdp->iosize2 > 0)
2082 release_region(brdp->ioaddr2, brdp->iosize2);
2084 release_region(brdp->ioaddr1, brdp->iosize1);
2089 /*****************************************************************************/
2092 * Initialize and configure the specified board.
2093 * Scan through all the boards in the configuration and see what we
2094 * can find. Handle EIO and the ECH boards a little differently here
2095 * since the initial search and setup is very different.
2098 static int __devinit stl_brdinit(struct stlbrd *brdp)
2102 pr_debug("stl_brdinit(brdp=%p)\n", brdp);
2104 switch (brdp->brdtype) {
2107 retval = stl_initeio(brdp);
2115 retval = stl_initech(brdp);
2120 printk("STALLION: board=%d is unknown board type=%d\n",
2121 brdp->brdnr, brdp->brdtype);
2126 if ((brdp->state & BRD_FOUND) == 0) {
2127 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2128 stl_brdnames[brdp->brdtype], brdp->brdnr,
2129 brdp->ioaddr1, brdp->irq);
2133 for (i = 0; i < STL_MAXPANELS; i++)
2134 if (brdp->panels[i] != NULL)
2135 stl_initports(brdp, brdp->panels[i]);
2137 printk("STALLION: %s found, board=%d io=%x irq=%d "
2138 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2139 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2144 free_irq(brdp->irq, brdp);
2146 stl_cleanup_panels(brdp);
2148 release_region(brdp->ioaddr1, brdp->iosize1);
2149 if (brdp->iosize2 > 0)
2150 release_region(brdp->ioaddr2, brdp->iosize2);
2155 /*****************************************************************************/
2158 * Find the next available board number that is free.
2161 static int __devinit stl_getbrdnr(void)
2165 for (i = 0; i < STL_MAXBRDS; i++)
2166 if (stl_brds[i] == NULL) {
2167 if (i >= stl_nrbrds)
2175 /*****************************************************************************/
2177 * We have a Stallion board. Allocate a board structure and
2178 * initialize it. Read its IO and IRQ resources from PCI
2179 * configuration space.
2182 static int __devinit stl_pciprobe(struct pci_dev *pdev,
2183 const struct pci_device_id *ent)
2185 struct stlbrd *brdp;
2186 unsigned int i, brdtype = ent->driver_data;
2187 int brdnr, retval = -ENODEV;
2189 if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2192 retval = pci_enable_device(pdev);
2195 brdp = stl_allocbrd();
2200 mutex_lock(&stl_brdslock);
2201 brdnr = stl_getbrdnr();
2203 dev_err(&pdev->dev, "too many boards found, "
2204 "maximum supported %d\n", STL_MAXBRDS);
2205 mutex_unlock(&stl_brdslock);
2209 brdp->brdnr = (unsigned int)brdnr;
2210 stl_brds[brdp->brdnr] = brdp;
2211 mutex_unlock(&stl_brdslock);
2213 brdp->brdtype = brdtype;
2214 brdp->state |= STL_PROBED;
2217 * We have all resources from the board, so let's setup the actual
2218 * board structure now.
2222 brdp->ioaddr2 = pci_resource_start(pdev, 0);
2223 brdp->ioaddr1 = pci_resource_start(pdev, 1);
2226 brdp->ioaddr2 = pci_resource_start(pdev, 2);
2227 brdp->ioaddr1 = pci_resource_start(pdev, 1);
2230 brdp->ioaddr1 = pci_resource_start(pdev, 2);
2231 brdp->ioaddr2 = pci_resource_start(pdev, 1);
2234 dev_err(&pdev->dev, "unknown PCI board type=%u\n", brdtype);
2238 brdp->irq = pdev->irq;
2239 retval = stl_brdinit(brdp);
2243 pci_set_drvdata(pdev, brdp);
2245 for (i = 0; i < brdp->nrports; i++)
2246 tty_register_device(stl_serial,
2247 brdp->brdnr * STL_MAXPORTS + i, &pdev->dev);
2251 stl_brds[brdp->brdnr] = NULL;
2258 static void __devexit stl_pciremove(struct pci_dev *pdev)
2260 struct stlbrd *brdp = pci_get_drvdata(pdev);
2263 free_irq(brdp->irq, brdp);
2265 stl_cleanup_panels(brdp);
2267 release_region(brdp->ioaddr1, brdp->iosize1);
2268 if (brdp->iosize2 > 0)
2269 release_region(brdp->ioaddr2, brdp->iosize2);
2271 for (i = 0; i < brdp->nrports; i++)
2272 tty_unregister_device(stl_serial,
2273 brdp->brdnr * STL_MAXPORTS + i);
2275 stl_brds[brdp->brdnr] = NULL;
2279 static struct pci_driver stl_pcidriver = {
2281 .id_table = stl_pcibrds,
2282 .probe = stl_pciprobe,
2283 .remove = __devexit_p(stl_pciremove)
2286 /*****************************************************************************/
2289 * Return the board stats structure to user app.
2292 static int stl_getbrdstats(combrd_t __user *bp)
2294 combrd_t stl_brdstats;
2295 struct stlbrd *brdp;
2296 struct stlpanel *panelp;
2299 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2301 if (stl_brdstats.brd >= STL_MAXBRDS)
2303 brdp = stl_brds[stl_brdstats.brd];
2307 memset(&stl_brdstats, 0, sizeof(combrd_t));
2308 stl_brdstats.brd = brdp->brdnr;
2309 stl_brdstats.type = brdp->brdtype;
2310 stl_brdstats.hwid = brdp->hwid;
2311 stl_brdstats.state = brdp->state;
2312 stl_brdstats.ioaddr = brdp->ioaddr1;
2313 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2314 stl_brdstats.irq = brdp->irq;
2315 stl_brdstats.nrpanels = brdp->nrpanels;
2316 stl_brdstats.nrports = brdp->nrports;
2317 for (i = 0; i < brdp->nrpanels; i++) {
2318 panelp = brdp->panels[i];
2319 stl_brdstats.panels[i].panel = i;
2320 stl_brdstats.panels[i].hwid = panelp->hwid;
2321 stl_brdstats.panels[i].nrports = panelp->nrports;
2324 return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
2327 /*****************************************************************************/
2330 * Resolve the referenced port number into a port struct pointer.
2333 static struct stlport *stl_getport(int brdnr, int panelnr, int portnr)
2335 struct stlbrd *brdp;
2336 struct stlpanel *panelp;
2338 if (brdnr < 0 || brdnr >= STL_MAXBRDS)
2340 brdp = stl_brds[brdnr];
2343 if (panelnr < 0 || (unsigned int)panelnr >= brdp->nrpanels)
2345 panelp = brdp->panels[panelnr];
2348 if (portnr < 0 || (unsigned int)portnr >= panelp->nrports)
2350 return panelp->ports[portnr];
2353 /*****************************************************************************/
2356 * Return the port stats structure to user app. A NULL port struct
2357 * pointer passed in means that we need to find out from the app
2358 * what port to get stats for (used through board control device).
2361 static int stl_getportstats(struct tty_struct *tty, struct stlport *portp, comstats_t __user *cp)
2363 comstats_t stl_comstats;
2364 unsigned char *head, *tail;
2365 unsigned long flags;
2368 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2370 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2376 portp->stats.state = portp->istate;
2377 portp->stats.flags = portp->port.flags;
2378 portp->stats.hwid = portp->hwid;
2380 portp->stats.ttystate = 0;
2381 portp->stats.cflags = 0;
2382 portp->stats.iflags = 0;
2383 portp->stats.oflags = 0;
2384 portp->stats.lflags = 0;
2385 portp->stats.rxbuffered = 0;
2387 spin_lock_irqsave(&stallion_lock, flags);
2388 if (tty != NULL && portp->port.tty == tty) {
2389 portp->stats.ttystate = tty->flags;
2390 /* No longer available as a statistic */
2391 portp->stats.rxbuffered = 1; /*tty->flip.count; */
2392 if (tty->termios != NULL) {
2393 portp->stats.cflags = tty->termios->c_cflag;
2394 portp->stats.iflags = tty->termios->c_iflag;
2395 portp->stats.oflags = tty->termios->c_oflag;
2396 portp->stats.lflags = tty->termios->c_lflag;
2399 spin_unlock_irqrestore(&stallion_lock, flags);
2401 head = portp->tx.head;
2402 tail = portp->tx.tail;
2403 portp->stats.txbuffered = (head >= tail) ? (head - tail) :
2404 (STL_TXBUFSIZE - (tail - head));
2406 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2408 return copy_to_user(cp, &portp->stats,
2409 sizeof(comstats_t)) ? -EFAULT : 0;
2412 /*****************************************************************************/
2415 * Clear the port stats structure. We also return it zeroed out...
2418 static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp)
2420 comstats_t stl_comstats;
2423 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2425 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2431 memset(&portp->stats, 0, sizeof(comstats_t));
2432 portp->stats.brd = portp->brdnr;
2433 portp->stats.panel = portp->panelnr;
2434 portp->stats.port = portp->portnr;
2435 return copy_to_user(cp, &portp->stats,
2436 sizeof(comstats_t)) ? -EFAULT : 0;
2439 /*****************************************************************************/
2442 * Return the entire driver ports structure to a user app.
2445 static int stl_getportstruct(struct stlport __user *arg)
2447 struct stlport stl_dummyport;
2448 struct stlport *portp;
2450 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
2452 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
2453 stl_dummyport.portnr);
2456 return copy_to_user(arg, portp, sizeof(struct stlport)) ? -EFAULT : 0;
2459 /*****************************************************************************/
2462 * Return the entire driver board structure to a user app.
2465 static int stl_getbrdstruct(struct stlbrd __user *arg)
2467 struct stlbrd stl_dummybrd;
2468 struct stlbrd *brdp;
2470 if (copy_from_user(&stl_dummybrd, arg, sizeof(struct stlbrd)))
2472 if (stl_dummybrd.brdnr >= STL_MAXBRDS)
2474 brdp = stl_brds[stl_dummybrd.brdnr];
2477 return copy_to_user(arg, brdp, sizeof(struct stlbrd)) ? -EFAULT : 0;
2480 /*****************************************************************************/
2483 * The "staliomem" device is also required to do some special operations
2484 * on the board and/or ports. In this driver it is mostly used for stats
2488 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
2491 void __user *argp = (void __user *)arg;
2493 pr_debug("stl_memioctl(ip=%p,fp=%p,cmd=%x,arg=%lx)\n", ip, fp, cmd,arg);
2496 if (brdnr >= STL_MAXBRDS)
2501 case COM_GETPORTSTATS:
2502 rc = stl_getportstats(NULL, NULL, argp);
2504 case COM_CLRPORTSTATS:
2505 rc = stl_clrportstats(NULL, argp);
2507 case COM_GETBRDSTATS:
2508 rc = stl_getbrdstats(argp);
2511 rc = stl_getportstruct(argp);
2514 rc = stl_getbrdstruct(argp);
2524 static const struct tty_operations stl_ops = {
2528 .put_char = stl_putchar,
2529 .flush_chars = stl_flushchars,
2530 .write_room = stl_writeroom,
2531 .chars_in_buffer = stl_charsinbuffer,
2533 .set_termios = stl_settermios,
2534 .throttle = stl_throttle,
2535 .unthrottle = stl_unthrottle,
2538 .hangup = stl_hangup,
2539 .flush_buffer = stl_flushbuffer,
2540 .break_ctl = stl_breakctl,
2541 .wait_until_sent = stl_waituntilsent,
2542 .send_xchar = stl_sendxchar,
2543 .tiocmget = stl_tiocmget,
2544 .tiocmset = stl_tiocmset,
2545 .proc_fops = &stl_proc_fops,
2548 static const struct tty_port_operations stl_port_ops = {
2549 .carrier_raised = stl_carrier_raised,
2550 .dtr_rts = stl_dtr_rts,
2553 /*****************************************************************************/
2554 /* CD1400 HARDWARE FUNCTIONS */
2555 /*****************************************************************************/
2558 * These functions get/set/update the registers of the cd1400 UARTs.
2559 * Access to the cd1400 registers is via an address/data io port pair.
2560 * (Maybe should make this inline...)
2563 static int stl_cd1400getreg(struct stlport *portp, int regnr)
2565 outb((regnr + portp->uartaddr), portp->ioaddr);
2566 return inb(portp->ioaddr + EREG_DATA);
2569 static void stl_cd1400setreg(struct stlport *portp, int regnr, int value)
2571 outb(regnr + portp->uartaddr, portp->ioaddr);
2572 outb(value, portp->ioaddr + EREG_DATA);
2575 static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value)
2577 outb(regnr + portp->uartaddr, portp->ioaddr);
2578 if (inb(portp->ioaddr + EREG_DATA) != value) {
2579 outb(value, portp->ioaddr + EREG_DATA);
2585 /*****************************************************************************/
2588 * Inbitialize the UARTs in a panel. We don't care what sort of board
2589 * these ports are on - since the port io registers are almost
2590 * identical when dealing with ports.
2593 static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
2597 int nrchips, uartaddr, ioaddr;
2598 unsigned long flags;
2600 pr_debug("stl_panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
2602 spin_lock_irqsave(&brd_lock, flags);
2603 BRDENABLE(panelp->brdnr, panelp->pagenr);
2606 * Check that each chip is present and started up OK.
2609 nrchips = panelp->nrports / CD1400_PORTS;
2610 for (i = 0; i < nrchips; i++) {
2611 if (brdp->brdtype == BRD_ECHPCI) {
2612 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
2613 ioaddr = panelp->iobase;
2615 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
2616 uartaddr = (i & 0x01) ? 0x080 : 0;
2617 outb((GFRCR + uartaddr), ioaddr);
2618 outb(0, (ioaddr + EREG_DATA));
2619 outb((CCR + uartaddr), ioaddr);
2620 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
2621 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
2622 outb((GFRCR + uartaddr), ioaddr);
2623 for (j = 0; j < CCR_MAXWAIT; j++)
2624 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
2627 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
2628 printk("STALLION: cd1400 not responding, "
2629 "brd=%d panel=%d chip=%d\n",
2630 panelp->brdnr, panelp->panelnr, i);
2633 chipmask |= (0x1 << i);
2634 outb((PPR + uartaddr), ioaddr);
2635 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
2638 BRDDISABLE(panelp->brdnr);
2639 spin_unlock_irqrestore(&brd_lock, flags);
2643 /*****************************************************************************/
2646 * Initialize hardware specific port registers.
2649 static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
2651 unsigned long flags;
2652 pr_debug("stl_cd1400portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
2655 if ((brdp == NULL) || (panelp == NULL) ||
2659 spin_lock_irqsave(&brd_lock, flags);
2660 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
2661 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
2662 portp->uartaddr = (portp->portnr & 0x04) << 5;
2663 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
2665 BRDENABLE(portp->brdnr, portp->pagenr);
2666 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2667 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
2668 portp->hwid = stl_cd1400getreg(portp, GFRCR);
2669 BRDDISABLE(portp->brdnr);
2670 spin_unlock_irqrestore(&brd_lock, flags);
2673 /*****************************************************************************/
2676 * Wait for the command register to be ready. We will poll this,
2677 * since it won't usually take too long to be ready.
2680 static void stl_cd1400ccrwait(struct stlport *portp)
2684 for (i = 0; i < CCR_MAXWAIT; i++)
2685 if (stl_cd1400getreg(portp, CCR) == 0)
2688 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
2689 portp->portnr, portp->panelnr, portp->brdnr);
2692 /*****************************************************************************/
2695 * Set up the cd1400 registers for a port based on the termios port
2699 static void stl_cd1400setport(struct stlport *portp, struct ktermios *tiosp)
2701 struct stlbrd *brdp;
2702 unsigned long flags;
2703 unsigned int clkdiv, baudrate;
2704 unsigned char cor1, cor2, cor3;
2705 unsigned char cor4, cor5, ccr;
2706 unsigned char srer, sreron, sreroff;
2707 unsigned char mcor1, mcor2, rtpr;
2708 unsigned char clk, div;
2724 brdp = stl_brds[portp->brdnr];
2729 * Set up the RX char ignore mask with those RX error types we
2730 * can ignore. We can get the cd1400 to help us out a little here,
2731 * it will ignore parity errors and breaks for us.
2733 portp->rxignoremsk = 0;
2734 if (tiosp->c_iflag & IGNPAR) {
2735 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
2736 cor1 |= COR1_PARIGNORE;
2738 if (tiosp->c_iflag & IGNBRK) {
2739 portp->rxignoremsk |= ST_BREAK;
2740 cor4 |= COR4_IGNBRK;
2743 portp->rxmarkmsk = ST_OVERRUN;
2744 if (tiosp->c_iflag & (INPCK | PARMRK))
2745 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
2746 if (tiosp->c_iflag & BRKINT)
2747 portp->rxmarkmsk |= ST_BREAK;
2750 * Go through the char size, parity and stop bits and set all the
2751 * option register appropriately.
2753 switch (tiosp->c_cflag & CSIZE) {
2768 if (tiosp->c_cflag & CSTOPB)
2773 if (tiosp->c_cflag & PARENB) {
2774 if (tiosp->c_cflag & PARODD)
2775 cor1 |= (COR1_PARENB | COR1_PARODD);
2777 cor1 |= (COR1_PARENB | COR1_PAREVEN);
2779 cor1 |= COR1_PARNONE;
2783 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
2784 * space for hardware flow control and the like. This should be set to
2785 * VMIN. Also here we will set the RX data timeout to 10ms - this should
2786 * really be based on VTIME.
2788 cor3 |= FIFO_RXTHRESHOLD;
2792 * Calculate the baud rate timers. For now we will just assume that
2793 * the input and output baud are the same. Could have used a baud
2794 * table here, but this way we can generate virtually any baud rate
2797 baudrate = tiosp->c_cflag & CBAUD;
2798 if (baudrate & CBAUDEX) {
2799 baudrate &= ~CBAUDEX;
2800 if ((baudrate < 1) || (baudrate > 4))
2801 tiosp->c_cflag &= ~CBAUDEX;
2805 baudrate = stl_baudrates[baudrate];
2806 if ((tiosp->c_cflag & CBAUD) == B38400) {
2807 if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
2809 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
2811 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
2813 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
2815 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
2816 baudrate = (portp->baud_base / portp->custom_divisor);
2818 if (baudrate > STL_CD1400MAXBAUD)
2819 baudrate = STL_CD1400MAXBAUD;
2822 for (clk = 0; clk < CD1400_NUMCLKS; clk++) {
2823 clkdiv = (portp->clk / stl_cd1400clkdivs[clk]) / baudrate;
2827 div = (unsigned char) clkdiv;
2831 * Check what form of modem signaling is required and set it up.
2833 if ((tiosp->c_cflag & CLOCAL) == 0) {
2836 sreron |= SRER_MODEM;
2837 portp->port.flags |= ASYNC_CHECK_CD;
2839 portp->port.flags &= ~ASYNC_CHECK_CD;
2842 * Setup cd1400 enhanced modes if we can. In particular we want to
2843 * handle as much of the flow control as possible automatically. As
2844 * well as saving a few CPU cycles it will also greatly improve flow
2845 * control reliability.
2847 if (tiosp->c_iflag & IXON) {
2850 if (tiosp->c_iflag & IXANY)
2854 if (tiosp->c_cflag & CRTSCTS) {
2856 mcor1 |= FIFO_RTSTHRESHOLD;
2860 * All cd1400 register values calculated so go through and set
2864 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
2865 portp->portnr, portp->panelnr, portp->brdnr);
2866 pr_debug(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
2867 cor1, cor2, cor3, cor4, cor5);
2868 pr_debug(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
2869 mcor1, mcor2, rtpr, sreron, sreroff);
2870 pr_debug(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
2871 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
2872 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
2873 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
2875 spin_lock_irqsave(&brd_lock, flags);
2876 BRDENABLE(portp->brdnr, portp->pagenr);
2877 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
2878 srer = stl_cd1400getreg(portp, SRER);
2879 stl_cd1400setreg(portp, SRER, 0);
2880 if (stl_cd1400updatereg(portp, COR1, cor1))
2882 if (stl_cd1400updatereg(portp, COR2, cor2))
2884 if (stl_cd1400updatereg(portp, COR3, cor3))
2887 stl_cd1400ccrwait(portp);
2888 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
2890 stl_cd1400setreg(portp, COR4, cor4);
2891 stl_cd1400setreg(portp, COR5, cor5);
2892 stl_cd1400setreg(portp, MCOR1, mcor1);
2893 stl_cd1400setreg(portp, MCOR2, mcor2);
2895 stl_cd1400setreg(portp, TCOR, clk);
2896 stl_cd1400setreg(portp, TBPR, div);
2897 stl_cd1400setreg(portp, RCOR, clk);
2898 stl_cd1400setreg(portp, RBPR, div);
2900 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
2901 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
2902 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
2903 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
2904 stl_cd1400setreg(portp, RTPR, rtpr);
2905 mcor1 = stl_cd1400getreg(portp, MSVR1);
2906 if (mcor1 & MSVR1_DCD)
2907 portp->sigs |= TIOCM_CD;
2909 portp->sigs &= ~TIOCM_CD;
2910 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
2911 BRDDISABLE(portp->brdnr);
2912 spin_unlock_irqrestore(&brd_lock, flags);
2915 /*****************************************************************************/
2918 * Set the state of the DTR and RTS signals.
2921 static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts)
2923 unsigned char msvr1, msvr2;
2924 unsigned long flags;
2926 pr_debug("stl_cd1400setsignals(portp=%p,dtr=%d,rts=%d)\n",
2936 spin_lock_irqsave(&brd_lock, flags);
2937 BRDENABLE(portp->brdnr, portp->pagenr);
2938 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2940 stl_cd1400setreg(portp, MSVR2, msvr2);
2942 stl_cd1400setreg(portp, MSVR1, msvr1);
2943 BRDDISABLE(portp->brdnr);
2944 spin_unlock_irqrestore(&brd_lock, flags);
2947 /*****************************************************************************/
2950 * Return the state of the signals.
2953 static int stl_cd1400getsignals(struct stlport *portp)
2955 unsigned char msvr1, msvr2;
2956 unsigned long flags;
2959 pr_debug("stl_cd1400getsignals(portp=%p)\n", portp);
2961 spin_lock_irqsave(&brd_lock, flags);
2962 BRDENABLE(portp->brdnr, portp->pagenr);
2963 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2964 msvr1 = stl_cd1400getreg(portp, MSVR1);
2965 msvr2 = stl_cd1400getreg(portp, MSVR2);
2966 BRDDISABLE(portp->brdnr);
2967 spin_unlock_irqrestore(&brd_lock, flags);
2970 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
2971 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
2972 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
2973 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
2975 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
2976 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
2983 /*****************************************************************************/
2986 * Enable/Disable the Transmitter and/or Receiver.
2989 static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx)
2992 unsigned long flags;
2994 pr_debug("stl_cd1400enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
2999 ccr |= CCR_TXDISABLE;
3001 ccr |= CCR_TXENABLE;
3003 ccr |= CCR_RXDISABLE;
3005 ccr |= CCR_RXENABLE;
3007 spin_lock_irqsave(&brd_lock, flags);
3008 BRDENABLE(portp->brdnr, portp->pagenr);
3009 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3010 stl_cd1400ccrwait(portp);
3011 stl_cd1400setreg(portp, CCR, ccr);
3012 stl_cd1400ccrwait(portp);
3013 BRDDISABLE(portp->brdnr);
3014 spin_unlock_irqrestore(&brd_lock, flags);
3017 /*****************************************************************************/
3020 * Start/stop the Transmitter and/or Receiver.
3023 static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx)
3025 unsigned char sreron, sreroff;
3026 unsigned long flags;
3028 pr_debug("stl_cd1400startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
3033 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3035 sreron |= SRER_TXDATA;
3037 sreron |= SRER_TXEMPTY;
3039 sreroff |= SRER_RXDATA;
3041 sreron |= SRER_RXDATA;
3043 spin_lock_irqsave(&brd_lock, flags);
3044 BRDENABLE(portp->brdnr, portp->pagenr);
3045 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3046 stl_cd1400setreg(portp, SRER,
3047 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3048 BRDDISABLE(portp->brdnr);
3050 set_bit(ASYI_TXBUSY, &portp->istate);
3051 spin_unlock_irqrestore(&brd_lock, flags);
3054 /*****************************************************************************/
3057 * Disable all interrupts from this port.
3060 static void stl_cd1400disableintrs(struct stlport *portp)
3062 unsigned long flags;
3064 pr_debug("stl_cd1400disableintrs(portp=%p)\n", portp);
3066 spin_lock_irqsave(&brd_lock, flags);
3067 BRDENABLE(portp->brdnr, portp->pagenr);
3068 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3069 stl_cd1400setreg(portp, SRER, 0);
3070 BRDDISABLE(portp->brdnr);
3071 spin_unlock_irqrestore(&brd_lock, flags);
3074 /*****************************************************************************/
3076 static void stl_cd1400sendbreak(struct stlport *portp, int len)
3078 unsigned long flags;
3080 pr_debug("stl_cd1400sendbreak(portp=%p,len=%d)\n", portp, len);
3082 spin_lock_irqsave(&brd_lock, flags);
3083 BRDENABLE(portp->brdnr, portp->pagenr);
3084 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3085 stl_cd1400setreg(portp, SRER,
3086 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3088 BRDDISABLE(portp->brdnr);
3089 portp->brklen = len;
3091 portp->stats.txbreaks++;
3092 spin_unlock_irqrestore(&brd_lock, flags);
3095 /*****************************************************************************/
3098 * Take flow control actions...
3101 static void stl_cd1400flowctrl(struct stlport *portp, int state)
3103 struct tty_struct *tty;
3104 unsigned long flags;
3106 pr_debug("stl_cd1400flowctrl(portp=%p,state=%x)\n", portp, state);
3110 tty = tty_port_tty_get(&portp->port);
3114 spin_lock_irqsave(&brd_lock, flags);
3115 BRDENABLE(portp->brdnr, portp->pagenr);
3116 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3119 if (tty->termios->c_iflag & IXOFF) {
3120 stl_cd1400ccrwait(portp);
3121 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3122 portp->stats.rxxon++;
3123 stl_cd1400ccrwait(portp);
3126 * Question: should we return RTS to what it was before? It may
3127 * have been set by an ioctl... Suppose not, since if you have
3128 * hardware flow control set then it is pretty silly to go and
3129 * set the RTS line by hand.
3131 if (tty->termios->c_cflag & CRTSCTS) {
3132 stl_cd1400setreg(portp, MCOR1,
3133 (stl_cd1400getreg(portp, MCOR1) |
3134 FIFO_RTSTHRESHOLD));
3135 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3136 portp->stats.rxrtson++;
3139 if (tty->termios->c_iflag & IXOFF) {
3140 stl_cd1400ccrwait(portp);
3141 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3142 portp->stats.rxxoff++;
3143 stl_cd1400ccrwait(portp);
3145 if (tty->termios->c_cflag & CRTSCTS) {
3146 stl_cd1400setreg(portp, MCOR1,
3147 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3148 stl_cd1400setreg(portp, MSVR2, 0);
3149 portp->stats.rxrtsoff++;
3153 BRDDISABLE(portp->brdnr);
3154 spin_unlock_irqrestore(&brd_lock, flags);
3158 /*****************************************************************************/
3161 * Send a flow control character...
3164 static void stl_cd1400sendflow(struct stlport *portp, int state)
3166 struct tty_struct *tty;
3167 unsigned long flags;
3169 pr_debug("stl_cd1400sendflow(portp=%p,state=%x)\n", portp, state);
3173 tty = tty_port_tty_get(&portp->port);
3177 spin_lock_irqsave(&brd_lock, flags);
3178 BRDENABLE(portp->brdnr, portp->pagenr);
3179 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3181 stl_cd1400ccrwait(portp);
3182 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3183 portp->stats.rxxon++;
3184 stl_cd1400ccrwait(portp);
3186 stl_cd1400ccrwait(portp);
3187 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3188 portp->stats.rxxoff++;
3189 stl_cd1400ccrwait(portp);
3191 BRDDISABLE(portp->brdnr);
3192 spin_unlock_irqrestore(&brd_lock, flags);
3196 /*****************************************************************************/
3198 static void stl_cd1400flush(struct stlport *portp)
3200 unsigned long flags;
3202 pr_debug("stl_cd1400flush(portp=%p)\n", portp);
3207 spin_lock_irqsave(&brd_lock, flags);
3208 BRDENABLE(portp->brdnr, portp->pagenr);
3209 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3210 stl_cd1400ccrwait(portp);
3211 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3212 stl_cd1400ccrwait(portp);
3213 portp->tx.tail = portp->tx.head;
3214 BRDDISABLE(portp->brdnr);
3215 spin_unlock_irqrestore(&brd_lock, flags);
3218 /*****************************************************************************/
3221 * Return the current state of data flow on this port. This is only
3222 * really interresting when determining if data has fully completed
3223 * transmission or not... This is easy for the cd1400, it accurately
3224 * maintains the busy port flag.
3227 static int stl_cd1400datastate(struct stlport *portp)
3229 pr_debug("stl_cd1400datastate(portp=%p)\n", portp);
3234 return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
3237 /*****************************************************************************/
3240 * Interrupt service routine for cd1400 EasyIO boards.
3243 static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase)
3245 unsigned char svrtype;
3247 pr_debug("stl_cd1400eiointr(panelp=%p,iobase=%x)\n", panelp, iobase);
3249 spin_lock(&brd_lock);
3251 svrtype = inb(iobase + EREG_DATA);
3252 if (panelp->nrports > 4) {
3253 outb((SVRR + 0x80), iobase);
3254 svrtype |= inb(iobase + EREG_DATA);
3257 if (svrtype & SVRR_RX)
3258 stl_cd1400rxisr(panelp, iobase);
3259 else if (svrtype & SVRR_TX)
3260 stl_cd1400txisr(panelp, iobase);
3261 else if (svrtype & SVRR_MDM)
3262 stl_cd1400mdmisr(panelp, iobase);
3264 spin_unlock(&brd_lock);
3267 /*****************************************************************************/
3270 * Interrupt service routine for cd1400 panels.
3273 static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase)
3275 unsigned char svrtype;
3277 pr_debug("stl_cd1400echintr(panelp=%p,iobase=%x)\n", panelp, iobase);
3280 svrtype = inb(iobase + EREG_DATA);
3281 outb((SVRR + 0x80), iobase);
3282 svrtype |= inb(iobase + EREG_DATA);
3283 if (svrtype & SVRR_RX)
3284 stl_cd1400rxisr(panelp, iobase);
3285 else if (svrtype & SVRR_TX)
3286 stl_cd1400txisr(panelp, iobase);
3287 else if (svrtype & SVRR_MDM)
3288 stl_cd1400mdmisr(panelp, iobase);
3292 /*****************************************************************************/
3295 * Unfortunately we need to handle breaks in the TX data stream, since
3296 * this is the only way to generate them on the cd1400.
3299 static int stl_cd1400breakisr(struct stlport *portp, int ioaddr)
3301 if (portp->brklen == 1) {
3302 outb((COR2 + portp->uartaddr), ioaddr);
3303 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
3304 (ioaddr + EREG_DATA));
3305 outb((TDR + portp->uartaddr), ioaddr);
3306 outb(ETC_CMD, (ioaddr + EREG_DATA));
3307 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
3308 outb((SRER + portp->uartaddr), ioaddr);
3309 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
3310 (ioaddr + EREG_DATA));
3312 } else if (portp->brklen > 1) {
3313 outb((TDR + portp->uartaddr), ioaddr);
3314 outb(ETC_CMD, (ioaddr + EREG_DATA));
3315 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
3319 outb((COR2 + portp->uartaddr), ioaddr);
3320 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
3321 (ioaddr + EREG_DATA));
3327 /*****************************************************************************/
3330 * Transmit interrupt handler. This has gotta be fast! Handling TX
3331 * chars is pretty simple, stuff as many as possible from the TX buffer
3332 * into the cd1400 FIFO. Must also handle TX breaks here, since they
3333 * are embedded as commands in the data stream. Oh no, had to use a goto!
3334 * This could be optimized more, will do when I get time...
3335 * In practice it is possible that interrupts are enabled but that the
3336 * port has been hung up. Need to handle not having any TX buffer here,
3337 * this is done by using the side effect that head and tail will also
3338 * be NULL if the buffer has been freed.
3341 static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr)
3343 struct stlport *portp;
3346 unsigned char ioack, srer;
3347 struct tty_struct *tty;
3349 pr_debug("stl_cd1400txisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3351 ioack = inb(ioaddr + EREG_TXACK);
3352 if (((ioack & panelp->ackmask) != 0) ||
3353 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
3354 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
3357 portp = panelp->ports[(ioack >> 3)];
3360 * Unfortunately we need to handle breaks in the data stream, since
3361 * this is the only way to generate them on the cd1400. Do it now if
3362 * a break is to be sent.
3364 if (portp->brklen != 0)
3365 if (stl_cd1400breakisr(portp, ioaddr))
3368 head = portp->tx.head;
3369 tail = portp->tx.tail;
3370 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
3371 if ((len == 0) || ((len < STL_TXBUFLOW) &&
3372 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
3373 set_bit(ASYI_TXLOW, &portp->istate);
3374 tty = tty_port_tty_get(&portp->port);
3382 outb((SRER + portp->uartaddr), ioaddr);
3383 srer = inb(ioaddr + EREG_DATA);
3384 if (srer & SRER_TXDATA) {
3385 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
3387 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
3388 clear_bit(ASYI_TXBUSY, &portp->istate);
3390 outb(srer, (ioaddr + EREG_DATA));
3392 len = min(len, CD1400_TXFIFOSIZE);
3393 portp->stats.txtotal += len;
3394 stlen = min_t(unsigned int, len,
3395 (portp->tx.buf + STL_TXBUFSIZE) - tail);
3396 outb((TDR + portp->uartaddr), ioaddr);
3397 outsb((ioaddr + EREG_DATA), tail, stlen);
3400 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
3401 tail = portp->tx.buf;
3403 outsb((ioaddr + EREG_DATA), tail, len);
3406 portp->tx.tail = tail;
3410 outb((EOSRR + portp->uartaddr), ioaddr);
3411 outb(0, (ioaddr + EREG_DATA));
3414 /*****************************************************************************/
3417 * Receive character interrupt handler. Determine if we have good chars
3418 * or bad chars and then process appropriately. Good chars are easy
3419 * just shove the lot into the RX buffer and set all status byte to 0.
3420 * If a bad RX char then process as required. This routine needs to be
3421 * fast! In practice it is possible that we get an interrupt on a port
3422 * that is closed. This can happen on hangups - since they completely
3423 * shutdown a port not in user context. Need to handle this case.
3426 static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr)
3428 struct stlport *portp;
3429 struct tty_struct *tty;
3430 unsigned int ioack, len, buflen;
3431 unsigned char status;
3434 pr_debug("stl_cd1400rxisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3436 ioack = inb(ioaddr + EREG_RXACK);
3437 if ((ioack & panelp->ackmask) != 0) {
3438 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
3441 portp = panelp->ports[(ioack >> 3)];
3442 tty = tty_port_tty_get(&portp->port);
3444 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
3445 outb((RDCR + portp->uartaddr), ioaddr);
3446 len = inb(ioaddr + EREG_DATA);
3447 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
3448 len = min_t(unsigned int, len, sizeof(stl_unwanted));
3449 outb((RDSR + portp->uartaddr), ioaddr);
3450 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
3451 portp->stats.rxlost += len;
3452 portp->stats.rxtotal += len;
3454 len = min(len, buflen);
3457 outb((RDSR + portp->uartaddr), ioaddr);
3458 tty_prepare_flip_string(tty, &ptr, len);
3459 insb((ioaddr + EREG_DATA), ptr, len);
3460 tty_schedule_flip(tty);
3461 portp->stats.rxtotal += len;
3464 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
3465 outb((RDSR + portp->uartaddr), ioaddr);
3466 status = inb(ioaddr + EREG_DATA);
3467 ch = inb(ioaddr + EREG_DATA);
3468 if (status & ST_PARITY)
3469 portp->stats.rxparity++;
3470 if (status & ST_FRAMING)
3471 portp->stats.rxframing++;
3472 if (status & ST_OVERRUN)
3473 portp->stats.rxoverrun++;
3474 if (status & ST_BREAK)
3475 portp->stats.rxbreaks++;
3476 if (status & ST_SCHARMASK) {
3477 if ((status & ST_SCHARMASK) == ST_SCHAR1)
3478 portp->stats.txxon++;
3479 if ((status & ST_SCHARMASK) == ST_SCHAR2)
3480 portp->stats.txxoff++;
3483 if (tty != NULL && (portp->rxignoremsk & status) == 0) {
3484 if (portp->rxmarkmsk & status) {
3485 if (status & ST_BREAK) {
3487 if (portp->port.flags & ASYNC_SAK) {
3489 BRDENABLE(portp->brdnr, portp->pagenr);
3491 } else if (status & ST_PARITY)
3492 status = TTY_PARITY;
3493 else if (status & ST_FRAMING)
3495 else if(status & ST_OVERRUN)
3496 status = TTY_OVERRUN;
3501 tty_insert_flip_char(tty, ch, status);
3502 tty_schedule_flip(tty);
3505 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
3512 outb((EOSRR + portp->uartaddr), ioaddr);
3513 outb(0, (ioaddr + EREG_DATA));
3516 /*****************************************************************************/
3519 * Modem interrupt handler. The is called when the modem signal line
3520 * (DCD) has changed state. Leave most of the work to the off-level
3521 * processing routine.
3524 static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr)
3526 struct stlport *portp;
3530 pr_debug("stl_cd1400mdmisr(panelp=%p)\n", panelp);
3532 ioack = inb(ioaddr + EREG_MDACK);
3533 if (((ioack & panelp->ackmask) != 0) ||
3534 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
3535 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
3538 portp = panelp->ports[(ioack >> 3)];
3540 outb((MISR + portp->uartaddr), ioaddr);
3541 misr = inb(ioaddr + EREG_DATA);
3542 if (misr & MISR_DCD) {
3543 stl_cd_change(portp);
3544 portp->stats.modem++;
3547 outb((EOSRR + portp->uartaddr), ioaddr);
3548 outb(0, (ioaddr + EREG_DATA));
3551 /*****************************************************************************/
3552 /* SC26198 HARDWARE FUNCTIONS */
3553 /*****************************************************************************/
3556 * These functions get/set/update the registers of the sc26198 UARTs.
3557 * Access to the sc26198 registers is via an address/data io port pair.
3558 * (Maybe should make this inline...)
3561 static int stl_sc26198getreg(struct stlport *portp, int regnr)
3563 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3564 return inb(portp->ioaddr + XP_DATA);
3567 static void stl_sc26198setreg(struct stlport *portp, int regnr, int value)
3569 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3570 outb(value, (portp->ioaddr + XP_DATA));
3573 static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value)
3575 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3576 if (inb(portp->ioaddr + XP_DATA) != value) {
3577 outb(value, (portp->ioaddr + XP_DATA));
3583 /*****************************************************************************/
3586 * Functions to get and set the sc26198 global registers.
3589 static int stl_sc26198getglobreg(struct stlport *portp, int regnr)
3591 outb(regnr, (portp->ioaddr + XP_ADDR));
3592 return inb(portp->ioaddr + XP_DATA);
3596 static void stl_sc26198setglobreg(struct stlport *portp, int regnr, int value)
3598 outb(regnr, (portp->ioaddr + XP_ADDR));
3599 outb(value, (portp->ioaddr + XP_DATA));
3603 /*****************************************************************************/
3606 * Inbitialize the UARTs in a panel. We don't care what sort of board
3607 * these ports are on - since the port io registers are almost
3608 * identical when dealing with ports.
3611 static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
3614 int nrchips, ioaddr;
3616 pr_debug("stl_sc26198panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
3618 BRDENABLE(panelp->brdnr, panelp->pagenr);
3621 * Check that each chip is present and started up OK.
3624 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
3625 if (brdp->brdtype == BRD_ECHPCI)
3626 outb(panelp->pagenr, brdp->ioctrl);
3628 for (i = 0; i < nrchips; i++) {
3629 ioaddr = panelp->iobase + (i * 4);
3630 outb(SCCR, (ioaddr + XP_ADDR));
3631 outb(CR_RESETALL, (ioaddr + XP_DATA));
3632 outb(TSTR, (ioaddr + XP_ADDR));
3633 if (inb(ioaddr + XP_DATA) != 0) {
3634 printk("STALLION: sc26198 not responding, "
3635 "brd=%d panel=%d chip=%d\n",
3636 panelp->brdnr, panelp->panelnr, i);
3639 chipmask |= (0x1 << i);
3640 outb(GCCR, (ioaddr + XP_ADDR));
3641 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
3642 outb(WDTRCR, (ioaddr + XP_ADDR));
3643 outb(0xff, (ioaddr + XP_DATA));
3646 BRDDISABLE(panelp->brdnr);
3650 /*****************************************************************************/
3653 * Initialize hardware specific port registers.
3656 static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
3658 pr_debug("stl_sc26198portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
3661 if ((brdp == NULL) || (panelp == NULL) ||
3665 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
3666 portp->uartaddr = (portp->portnr & 0x07) << 4;
3667 portp->pagenr = panelp->pagenr;
3670 BRDENABLE(portp->brdnr, portp->pagenr);
3671 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
3672 BRDDISABLE(portp->brdnr);
3675 /*****************************************************************************/
3678 * Set up the sc26198 registers for a port based on the termios port
3682 static void stl_sc26198setport(struct stlport *portp, struct ktermios *tiosp)
3684 struct stlbrd *brdp;
3685 unsigned long flags;
3686 unsigned int baudrate;
3687 unsigned char mr0, mr1, mr2, clk;
3688 unsigned char imron, imroff, iopr, ipr;
3698 brdp = stl_brds[portp->brdnr];
3703 * Set up the RX char ignore mask with those RX error types we
3706 portp->rxignoremsk = 0;
3707 if (tiosp->c_iflag & IGNPAR)
3708 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
3710 if (tiosp->c_iflag & IGNBRK)
3711 portp->rxignoremsk |= SR_RXBREAK;
3713 portp->rxmarkmsk = SR_RXOVERRUN;
3714 if (tiosp->c_iflag & (INPCK | PARMRK))
3715 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
3716 if (tiosp->c_iflag & BRKINT)
3717 portp->rxmarkmsk |= SR_RXBREAK;
3720 * Go through the char size, parity and stop bits and set all the
3721 * option register appropriately.
3723 switch (tiosp->c_cflag & CSIZE) {
3738 if (tiosp->c_cflag & CSTOPB)
3743 if (tiosp->c_cflag & PARENB) {
3744 if (tiosp->c_cflag & PARODD)
3745 mr1 |= (MR1_PARENB | MR1_PARODD);
3747 mr1 |= (MR1_PARENB | MR1_PAREVEN);
3751 mr1 |= MR1_ERRBLOCK;
3754 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
3755 * space for hardware flow control and the like. This should be set to
3758 mr2 |= MR2_RXFIFOHALF;
3761 * Calculate the baud rate timers. For now we will just assume that
3762 * the input and output baud are the same. The sc26198 has a fixed
3763 * baud rate table, so only discrete baud rates possible.
3765 baudrate = tiosp->c_cflag & CBAUD;
3766 if (baudrate & CBAUDEX) {
3767 baudrate &= ~CBAUDEX;
3768 if ((baudrate < 1) || (baudrate > 4))
3769 tiosp->c_cflag &= ~CBAUDEX;
3773 baudrate = stl_baudrates[baudrate];
3774 if ((tiosp->c_cflag & CBAUD) == B38400) {
3775 if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3777 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3779 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3781 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3783 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3784 baudrate = (portp->baud_base / portp->custom_divisor);
3786 if (baudrate > STL_SC26198MAXBAUD)
3787 baudrate = STL_SC26198MAXBAUD;
3790 for (clk = 0; clk < SC26198_NRBAUDS; clk++)
3791 if (baudrate <= sc26198_baudtable[clk])
3795 * Check what form of modem signaling is required and set it up.
3797 if (tiosp->c_cflag & CLOCAL) {
3798 portp->port.flags &= ~ASYNC_CHECK_CD;
3800 iopr |= IOPR_DCDCOS;
3802 portp->port.flags |= ASYNC_CHECK_CD;
3806 * Setup sc26198 enhanced modes if we can. In particular we want to
3807 * handle as much of the flow control as possible automatically. As
3808 * well as saving a few CPU cycles it will also greatly improve flow
3809 * control reliability.
3811 if (tiosp->c_iflag & IXON) {
3812 mr0 |= MR0_SWFTX | MR0_SWFT;
3813 imron |= IR_XONXOFF;
3815 imroff |= IR_XONXOFF;
3817 if (tiosp->c_iflag & IXOFF)
3820 if (tiosp->c_cflag & CRTSCTS) {
3826 * All sc26198 register values calculated so go through and set
3830 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3831 portp->portnr, portp->panelnr, portp->brdnr);
3832 pr_debug(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
3833 pr_debug(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
3834 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3835 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3836 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3838 spin_lock_irqsave(&brd_lock, flags);
3839 BRDENABLE(portp->brdnr, portp->pagenr);
3840 stl_sc26198setreg(portp, IMR, 0);
3841 stl_sc26198updatereg(portp, MR0, mr0);
3842 stl_sc26198updatereg(portp, MR1, mr1);
3843 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
3844 stl_sc26198updatereg(portp, MR2, mr2);
3845 stl_sc26198updatereg(portp, IOPIOR,
3846 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
3849 stl_sc26198setreg(portp, TXCSR, clk);
3850 stl_sc26198setreg(portp, RXCSR, clk);
3853 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
3854 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
3856 ipr = stl_sc26198getreg(portp, IPR);
3858 portp->sigs &= ~TIOCM_CD;
3860 portp->sigs |= TIOCM_CD;
3862 portp->imr = (portp->imr & ~imroff) | imron;
3863 stl_sc26198setreg(portp, IMR, portp->imr);
3864 BRDDISABLE(portp->brdnr);
3865 spin_unlock_irqrestore(&brd_lock, flags);
3868 /*****************************************************************************/
3871 * Set the state of the DTR and RTS signals.
3874 static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts)
3876 unsigned char iopioron, iopioroff;
3877 unsigned long flags;
3879 pr_debug("stl_sc26198setsignals(portp=%p,dtr=%d,rts=%d)\n", portp,
3885 iopioroff |= IPR_DTR;
3887 iopioron |= IPR_DTR;
3889 iopioroff |= IPR_RTS;
3891 iopioron |= IPR_RTS;
3893 spin_lock_irqsave(&brd_lock, flags);
3894 BRDENABLE(portp->brdnr, portp->pagenr);
3895 stl_sc26198setreg(portp, IOPIOR,
3896 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
3897 BRDDISABLE(portp->brdnr);
3898 spin_unlock_irqrestore(&brd_lock, flags);
3901 /*****************************************************************************/
3904 * Return the state of the signals.
3907 static int stl_sc26198getsignals(struct stlport *portp)
3910 unsigned long flags;
3913 pr_debug("stl_sc26198getsignals(portp=%p)\n", portp);
3915 spin_lock_irqsave(&brd_lock, flags);
3916 BRDENABLE(portp->brdnr, portp->pagenr);
3917 ipr = stl_sc26198getreg(portp, IPR);
3918 BRDDISABLE(portp->brdnr);
3919 spin_unlock_irqrestore(&brd_lock, flags);
3922 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
3923 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
3924 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
3925 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
3930 /*****************************************************************************/
3933 * Enable/Disable the Transmitter and/or Receiver.
3936 static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx)
3939 unsigned long flags;
3941 pr_debug("stl_sc26198enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx,tx);
3943 ccr = portp->crenable;
3945 ccr &= ~CR_TXENABLE;
3949 ccr &= ~CR_RXENABLE;
3953 spin_lock_irqsave(&brd_lock, flags);
3954 BRDENABLE(portp->brdnr, portp->pagenr);
3955 stl_sc26198setreg(portp, SCCR, ccr);
3956 BRDDISABLE(portp->brdnr);
3957 portp->crenable = ccr;
3958 spin_unlock_irqrestore(&brd_lock, flags);
3961 /*****************************************************************************/
3964 * Start/stop the Transmitter and/or Receiver.
3967 static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx)
3970 unsigned long flags;
3972 pr_debug("stl_sc26198startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
3980 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
3982 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
3984 spin_lock_irqsave(&brd_lock, flags);
3985 BRDENABLE(portp->brdnr, portp->pagenr);
3986 stl_sc26198setreg(portp, IMR, imr);
3987 BRDDISABLE(portp->brdnr);
3990 set_bit(ASYI_TXBUSY, &portp->istate);
3991 spin_unlock_irqrestore(&brd_lock, flags);
3994 /*****************************************************************************/
3997 * Disable all interrupts from this port.
4000 static void stl_sc26198disableintrs(struct stlport *portp)
4002 unsigned long flags;
4004 pr_debug("stl_sc26198disableintrs(portp=%p)\n", portp);
4006 spin_lock_irqsave(&brd_lock, flags);
4007 BRDENABLE(portp->brdnr, portp->pagenr);
4009 stl_sc26198setreg(portp, IMR, 0);
4010 BRDDISABLE(portp->brdnr);
4011 spin_unlock_irqrestore(&brd_lock, flags);
4014 /*****************************************************************************/
4016 static void stl_sc26198sendbreak(struct stlport *portp, int len)
4018 unsigned long flags;
4020 pr_debug("stl_sc26198sendbreak(portp=%p,len=%d)\n", portp, len);
4022 spin_lock_irqsave(&brd_lock, flags);
4023 BRDENABLE(portp->brdnr, portp->pagenr);
4025 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4026 portp->stats.txbreaks++;
4028 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4030 BRDDISABLE(portp->brdnr);
4031 spin_unlock_irqrestore(&brd_lock, flags);
4034 /*****************************************************************************/
4037 * Take flow control actions...
4040 static void stl_sc26198flowctrl(struct stlport *portp, int state)
4042 struct tty_struct *tty;
4043 unsigned long flags;
4046 pr_debug("stl_sc26198flowctrl(portp=%p,state=%x)\n", portp, state);
4050 tty = tty_port_tty_get(&portp->port);
4054 spin_lock_irqsave(&brd_lock, flags);
4055 BRDENABLE(portp->brdnr, portp->pagenr);
4058 if (tty->termios->c_iflag & IXOFF) {
4059 mr0 = stl_sc26198getreg(portp, MR0);
4060 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4061 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4063 portp->stats.rxxon++;
4064 stl_sc26198wait(portp);
4065 stl_sc26198setreg(portp, MR0, mr0);
4068 * Question: should we return RTS to what it was before? It may
4069 * have been set by an ioctl... Suppose not, since if you have
4070 * hardware flow control set then it is pretty silly to go and
4071 * set the RTS line by hand.
4073 if (tty->termios->c_cflag & CRTSCTS) {
4074 stl_sc26198setreg(portp, MR1,
4075 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4076 stl_sc26198setreg(portp, IOPIOR,
4077 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4078 portp->stats.rxrtson++;
4081 if (tty->termios->c_iflag & IXOFF) {
4082 mr0 = stl_sc26198getreg(portp, MR0);
4083 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4084 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4086 portp->stats.rxxoff++;
4087 stl_sc26198wait(portp);
4088 stl_sc26198setreg(portp, MR0, mr0);
4090 if (tty->termios->c_cflag & CRTSCTS) {
4091 stl_sc26198setreg(portp, MR1,
4092 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4093 stl_sc26198setreg(portp, IOPIOR,
4094 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4095 portp->stats.rxrtsoff++;
4099 BRDDISABLE(portp->brdnr);
4100 spin_unlock_irqrestore(&brd_lock, flags);
4104 /*****************************************************************************/
4107 * Send a flow control character.
4110 static void stl_sc26198sendflow(struct stlport *portp, int state)
4112 struct tty_struct *tty;
4113 unsigned long flags;
4116 pr_debug("stl_sc26198sendflow(portp=%p,state=%x)\n", portp, state);
4120 tty = tty_port_tty_get(&portp->port);
4124 spin_lock_irqsave(&brd_lock, flags);
4125 BRDENABLE(portp->brdnr, portp->pagenr);
4127 mr0 = stl_sc26198getreg(portp, MR0);
4128 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4129 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4131 portp->stats.rxxon++;
4132 stl_sc26198wait(portp);
4133 stl_sc26198setreg(portp, MR0, mr0);
4135 mr0 = stl_sc26198getreg(portp, MR0);
4136 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4137 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4139 portp->stats.rxxoff++;
4140 stl_sc26198wait(portp);
4141 stl_sc26198setreg(portp, MR0, mr0);
4143 BRDDISABLE(portp->brdnr);
4144 spin_unlock_irqrestore(&brd_lock, flags);
4148 /*****************************************************************************/
4150 static void stl_sc26198flush(struct stlport *portp)
4152 unsigned long flags;
4154 pr_debug("stl_sc26198flush(portp=%p)\n", portp);
4159 spin_lock_irqsave(&brd_lock, flags);
4160 BRDENABLE(portp->brdnr, portp->pagenr);
4161 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4162 stl_sc26198setreg(portp, SCCR, portp->crenable);
4163 BRDDISABLE(portp->brdnr);
4164 portp->tx.tail = portp->tx.head;
4165 spin_unlock_irqrestore(&brd_lock, flags);
4168 /*****************************************************************************/
4171 * Return the current state of data flow on this port. This is only
4172 * really interresting when determining if data has fully completed
4173 * transmission or not... The sc26198 interrupt scheme cannot
4174 * determine when all data has actually drained, so we need to
4175 * check the port statusy register to be sure.
4178 static int stl_sc26198datastate(struct stlport *portp)
4180 unsigned long flags;
4183 pr_debug("stl_sc26198datastate(portp=%p)\n", portp);
4187 if (test_bit(ASYI_TXBUSY, &portp->istate))
4190 spin_lock_irqsave(&brd_lock, flags);
4191 BRDENABLE(portp->brdnr, portp->pagenr);
4192 sr = stl_sc26198getreg(portp, SR);
4193 BRDDISABLE(portp->brdnr);
4194 spin_unlock_irqrestore(&brd_lock, flags);
4196 return (sr & SR_TXEMPTY) ? 0 : 1;
4199 /*****************************************************************************/
4202 * Delay for a small amount of time, to give the sc26198 a chance
4203 * to process a command...
4206 static void stl_sc26198wait(struct stlport *portp)
4210 pr_debug("stl_sc26198wait(portp=%p)\n", portp);
4215 for (i = 0; i < 20; i++)
4216 stl_sc26198getglobreg(portp, TSTR);
4219 /*****************************************************************************/
4222 * If we are TX flow controlled and in IXANY mode then we may
4223 * need to unflow control here. We gotta do this because of the
4224 * automatic flow control modes of the sc26198.
4227 static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty)
4231 mr0 = stl_sc26198getreg(portp, MR0);
4232 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4233 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4234 stl_sc26198wait(portp);
4235 stl_sc26198setreg(portp, MR0, mr0);
4236 clear_bit(ASYI_TXFLOWED, &portp->istate);
4239 /*****************************************************************************/
4242 * Interrupt service routine for sc26198 panels.
4245 static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase)
4247 struct stlport *portp;
4250 spin_lock(&brd_lock);
4253 * Work around bug in sc26198 chip... Cannot have A6 address
4254 * line of UART high, else iack will be returned as 0.
4256 outb(0, (iobase + 1));
4258 iack = inb(iobase + XP_IACK);
4259 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4261 if (iack & IVR_RXDATA)
4262 stl_sc26198rxisr(portp, iack);
4263 else if (iack & IVR_TXDATA)
4264 stl_sc26198txisr(portp);
4266 stl_sc26198otherisr(portp, iack);
4268 spin_unlock(&brd_lock);
4271 /*****************************************************************************/
4274 * Transmit interrupt handler. This has gotta be fast! Handling TX
4275 * chars is pretty simple, stuff as many as possible from the TX buffer
4276 * into the sc26198 FIFO.
4277 * In practice it is possible that interrupts are enabled but that the
4278 * port has been hung up. Need to handle not having any TX buffer here,
4279 * this is done by using the side effect that head and tail will also
4280 * be NULL if the buffer has been freed.
4283 static void stl_sc26198txisr(struct stlport *portp)
4285 struct tty_struct *tty;
4286 unsigned int ioaddr;
4291 pr_debug("stl_sc26198txisr(portp=%p)\n", portp);
4293 ioaddr = portp->ioaddr;
4294 head = portp->tx.head;
4295 tail = portp->tx.tail;
4296 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4297 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4298 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4299 set_bit(ASYI_TXLOW, &portp->istate);
4300 tty = tty_port_tty_get(&portp->port);
4308 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
4309 mr0 = inb(ioaddr + XP_DATA);
4310 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4311 portp->imr &= ~IR_TXRDY;
4312 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
4313 outb(portp->imr, (ioaddr + XP_DATA));
4314 clear_bit(ASYI_TXBUSY, &portp->istate);
4316 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4317 outb(mr0, (ioaddr + XP_DATA));
4320 len = min(len, SC26198_TXFIFOSIZE);
4321 portp->stats.txtotal += len;
4322 stlen = min_t(unsigned int, len,
4323 (portp->tx.buf + STL_TXBUFSIZE) - tail);
4324 outb(GTXFIFO, (ioaddr + XP_ADDR));
4325 outsb((ioaddr + XP_DATA), tail, stlen);
4328 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4329 tail = portp->tx.buf;
4331 outsb((ioaddr + XP_DATA), tail, len);
4334 portp->tx.tail = tail;
4338 /*****************************************************************************/
4341 * Receive character interrupt handler. Determine if we have good chars
4342 * or bad chars and then process appropriately. Good chars are easy
4343 * just shove the lot into the RX buffer and set all status byte to 0.
4344 * If a bad RX char then process as required. This routine needs to be
4345 * fast! In practice it is possible that we get an interrupt on a port
4346 * that is closed. This can happen on hangups - since they completely
4347 * shutdown a port not in user context. Need to handle this case.
4350 static void stl_sc26198rxisr(struct stlport *portp, unsigned int iack)
4352 struct tty_struct *tty;
4353 unsigned int len, buflen, ioaddr;
4355 pr_debug("stl_sc26198rxisr(portp=%p,iack=%x)\n", portp, iack);
4357 tty = tty_port_tty_get(&portp->port);
4358 ioaddr = portp->ioaddr;
4359 outb(GIBCR, (ioaddr + XP_ADDR));
4360 len = inb(ioaddr + XP_DATA) + 1;
4362 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
4363 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
4364 len = min_t(unsigned int, len, sizeof(stl_unwanted));
4365 outb(GRXFIFO, (ioaddr + XP_ADDR));
4366 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4367 portp->stats.rxlost += len;
4368 portp->stats.rxtotal += len;
4370 len = min(len, buflen);
4373 outb(GRXFIFO, (ioaddr + XP_ADDR));
4374 tty_prepare_flip_string(tty, &ptr, len);
4375 insb((ioaddr + XP_DATA), ptr, len);
4376 tty_schedule_flip(tty);
4377 portp->stats.rxtotal += len;
4381 stl_sc26198rxbadchars(portp);
4385 * If we are TX flow controlled and in IXANY mode then we may need
4386 * to unflow control here. We gotta do this because of the automatic
4387 * flow control modes of the sc26198.
4389 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
4390 if ((tty != NULL) &&
4391 (tty->termios != NULL) &&
4392 (tty->termios->c_iflag & IXANY)) {
4393 stl_sc26198txunflow(portp, tty);
4399 /*****************************************************************************/
4402 * Process an RX bad character.
4405 static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch)
4407 struct tty_struct *tty;
4408 unsigned int ioaddr;
4410 tty = tty_port_tty_get(&portp->port);
4411 ioaddr = portp->ioaddr;
4413 if (status & SR_RXPARITY)
4414 portp->stats.rxparity++;
4415 if (status & SR_RXFRAMING)
4416 portp->stats.rxframing++;
4417 if (status & SR_RXOVERRUN)
4418 portp->stats.rxoverrun++;
4419 if (status & SR_RXBREAK)
4420 portp->stats.rxbreaks++;
4422 if ((tty != NULL) &&
4423 ((portp->rxignoremsk & status) == 0)) {
4424 if (portp->rxmarkmsk & status) {
4425 if (status & SR_RXBREAK) {
4427 if (portp->port.flags & ASYNC_SAK) {
4429 BRDENABLE(portp->brdnr, portp->pagenr);
4431 } else if (status & SR_RXPARITY)
4432 status = TTY_PARITY;
4433 else if (status & SR_RXFRAMING)
4435 else if(status & SR_RXOVERRUN)
4436 status = TTY_OVERRUN;
4442 tty_insert_flip_char(tty, ch, status);
4443 tty_schedule_flip(tty);
4446 portp->stats.rxtotal++;
4451 /*****************************************************************************/
4454 * Process all characters in the RX FIFO of the UART. Check all char
4455 * status bytes as well, and process as required. We need to check
4456 * all bytes in the FIFO, in case some more enter the FIFO while we
4457 * are here. To get the exact character error type we need to switch
4458 * into CHAR error mode (that is why we need to make sure we empty
4462 static void stl_sc26198rxbadchars(struct stlport *portp)
4464 unsigned char status, mr1;
4468 * To get the precise error type for each character we must switch
4469 * back into CHAR error mode.
4471 mr1 = stl_sc26198getreg(portp, MR1);
4472 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
4474 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
4475 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
4476 ch = stl_sc26198getreg(portp, RXFIFO);
4477 stl_sc26198rxbadch(portp, status, ch);
4481 * To get correct interrupt class we must switch back into BLOCK
4484 stl_sc26198setreg(portp, MR1, mr1);
4487 /*****************************************************************************/
4490 * Other interrupt handler. This includes modem signals, flow
4491 * control actions, etc. Most stuff is left to off-level interrupt
4495 static void stl_sc26198otherisr(struct stlport *portp, unsigned int iack)
4497 unsigned char cir, ipr, xisr;
4499 pr_debug("stl_sc26198otherisr(portp=%p,iack=%x)\n", portp, iack);
4501 cir = stl_sc26198getglobreg(portp, CIR);
4503 switch (cir & CIR_SUBTYPEMASK) {
4505 ipr = stl_sc26198getreg(portp, IPR);
4506 if (ipr & IPR_DCDCHANGE) {
4507 stl_cd_change(portp);
4508 portp->stats.modem++;
4511 case CIR_SUBXONXOFF:
4512 xisr = stl_sc26198getreg(portp, XISR);
4513 if (xisr & XISR_RXXONGOT) {
4514 set_bit(ASYI_TXFLOWED, &portp->istate);
4515 portp->stats.txxoff++;
4517 if (xisr & XISR_RXXOFFGOT) {
4518 clear_bit(ASYI_TXFLOWED, &portp->istate);
4519 portp->stats.txxon++;
4523 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
4524 stl_sc26198rxbadchars(portp);
4531 static void stl_free_isabrds(void)
4533 struct stlbrd *brdp;
4536 for (i = 0; i < stl_nrbrds; i++) {
4537 if ((brdp = stl_brds[i]) == NULL || (brdp->state & STL_PROBED))
4540 free_irq(brdp->irq, brdp);
4542 stl_cleanup_panels(brdp);
4544 release_region(brdp->ioaddr1, brdp->iosize1);
4545 if (brdp->iosize2 > 0)
4546 release_region(brdp->ioaddr2, brdp->iosize2);
4554 * Loadable module initialization stuff.
4556 static int __init stallion_module_init(void)
4558 struct stlbrd *brdp;
4559 struct stlconf conf;
4563 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
4565 spin_lock_init(&stallion_lock);
4566 spin_lock_init(&brd_lock);
4568 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
4574 stl_serial->owner = THIS_MODULE;
4575 stl_serial->driver_name = stl_drvname;
4576 stl_serial->name = "ttyE";
4577 stl_serial->major = STL_SERIALMAJOR;
4578 stl_serial->minor_start = 0;
4579 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
4580 stl_serial->subtype = SERIAL_TYPE_NORMAL;
4581 stl_serial->init_termios = stl_deftermios;
4582 stl_serial->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
4583 tty_set_operations(stl_serial, &stl_ops);
4585 retval = tty_register_driver(stl_serial);
4587 printk("STALLION: failed to register serial driver\n");
4592 * Find any dynamically supported boards. That is via module load
4595 for (i = stl_nrbrds; i < stl_nargs; i++) {
4596 memset(&conf, 0, sizeof(conf));
4597 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
4599 if ((brdp = stl_allocbrd()) == NULL)
4602 brdp->brdtype = conf.brdtype;
4603 brdp->ioaddr1 = conf.ioaddr1;
4604 brdp->ioaddr2 = conf.ioaddr2;
4605 brdp->irq = conf.irq;
4606 brdp->irqtype = conf.irqtype;
4607 stl_brds[brdp->brdnr] = brdp;
4608 if (stl_brdinit(brdp)) {
4609 stl_brds[brdp->brdnr] = NULL;
4612 for (j = 0; j < brdp->nrports; j++)
4613 tty_register_device(stl_serial,
4614 brdp->brdnr * STL_MAXPORTS + j, NULL);
4619 /* this has to be _after_ isa finding because of locking */
4620 retval = pci_register_driver(&stl_pcidriver);
4621 if (retval && stl_nrbrds == 0) {
4622 printk(KERN_ERR "STALLION: can't register pci driver\n");
4627 * Set up a character driver for per board stuff. This is mainly used
4628 * to do stats ioctls on the ports.
4630 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
4631 printk("STALLION: failed to register serial board device\n");
4633 stallion_class = class_create(THIS_MODULE, "staliomem");
4634 if (IS_ERR(stallion_class))
4635 printk("STALLION: failed to create class\n");
4636 for (i = 0; i < 4; i++)
4637 device_create(stallion_class, NULL, MKDEV(STL_SIOMEMMAJOR, i),
4638 NULL, "staliomem%d", i);
4642 tty_unregister_driver(stl_serial);
4644 put_tty_driver(stl_serial);
4649 static void __exit stallion_module_exit(void)
4651 struct stlbrd *brdp;
4654 pr_debug("cleanup_module()\n");
4656 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
4660 * Free up all allocated resources used by the ports. This includes
4661 * memory and interrupts. As part of this process we will also do
4662 * a hangup on every open port - to try to flush out any processes
4663 * hanging onto ports.
4665 for (i = 0; i < stl_nrbrds; i++) {
4666 if ((brdp = stl_brds[i]) == NULL || (brdp->state & STL_PROBED))
4668 for (j = 0; j < brdp->nrports; j++)
4669 tty_unregister_device(stl_serial,
4670 brdp->brdnr * STL_MAXPORTS + j);
4673 for (i = 0; i < 4; i++)
4674 device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
4675 unregister_chrdev(STL_SIOMEMMAJOR, "staliomem");
4676 class_destroy(stallion_class);
4678 pci_unregister_driver(&stl_pcidriver);
4682 tty_unregister_driver(stl_serial);
4683 put_tty_driver(stl_serial);
4686 module_init(stallion_module_init);
4687 module_exit(stallion_module_exit);
4689 MODULE_AUTHOR("Greg Ungerer");
4690 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
4691 MODULE_LICENSE("GPL");